2013-01-01 47 views
0

我正試圖將excel導出爲pdf
我正在使用C#。爲什麼ExportAsFixedFormat中的param paramIgnorePrintAreas不起作用?

我遇到了問題ExportAsFixedFormat。我的文檔有打印區域(在Excel應用程序中設置,如果手動發送打印,它們也可以工作)。但它在我的程序中不起作用。我將參數paramIgnorePrintAreas設置爲false,但沒有幫助。

public void createXls(){ 
    ApplicationClass excelApplication = new ApplicationClass(); 
    Workbook excelWorkBook = null; 
    //Worksheet excelWorksheet = null; 
    excelApplication.ScreenUpdating = false; 
    excelApplication.Visible = false; 

    string paramSourceBookPath = @"C:\Temp\Test.xlsx"; 
    object paramMissing = Type.Missing; 
    string paramExportFilePath = @"C:\Temp\Test.pdf"; 
    XlFixedFormatType paramExportFormat = XlFixedFormatType.xlTypePDF; 
    XlFixedFormatQuality paramExportQuality = XlFixedFormatQuality.xlQualityStandard; 
    bool paramOpenAfterPublish = false; 
    bool paramIncludeDocProps = true; 
    bool paramIgnorePrintAreas = false; 
    object paramFromPage = Type.Missing; 
    object paramToPage = Type.Missing; 
    try 
    { 
     // Open the source workbook. 
     excelWorkBook = excelApplication.Workbooks.Open(paramSourceBookPath, 
     false, paramMissing, paramMissing, paramMissing, 
     paramMissing, paramMissing, paramMissing, paramMissing, 
     paramMissing, paramMissing, paramMissing, paramMissing, 
     paramMissing, paramMissing); 

    // Save it in the target format. 
     if (excelWorkBook != null) 
     { 
      Worksheet excelWorksheet = (Worksheet) excelWorkBook.ActiveSheet; 
      excelWorksheet.ExportAsFixedFormat(paramExportFormat, 
      paramExportFilePath, paramExportQuality, 
      paramIncludeDocProps, paramIgnorePrintAreas, paramFromPage, 
      paramToPage, paramOpenAfterPublish, 
      paramMissing); 
     } 
    } catch (Exception ex) 
    { 
    //richTextBox1.Text=ex.Message.ToString(); 
    } 
    finally 
    { 
     // Close the workbook object. 
     if (excelWorkBook != null) 
     { 
      excelWorkBook.Close(false, paramMissing, paramMissing); 
      excelWorkBook = null; 
     } 

     // Quit Excel and release the ApplicationClass object. 
     if (excelApplication != null) 
     { 
      excelApplication.Quit(); 
      excelApplication = null; 
     } 

     GC.Collect(); 
     GC.WaitForPendingFinalizers(); 
     GC.Collect(); 
     GC.WaitForPendingFinalizers(); 
    } 
} 

回答

1

只是嘗試重新設置打印區域,在出口前:

excelWorksheet.PageSetup.PrintArea = "Print_Area"; 

我這是造成的,我認爲類似的問題,因爲它是Excel和國際版本的命令修復輸出格式。

相關問題