にエクスポートしようとしexcel
ていpdf
ます。
私はC#を使用しています。
に問題がありExportAsFixedFormat
ます。私のドキュメントには印刷領域があります (Excel アプリケーションで設定され、手動で印刷する場合に機能します)。しかし、私のプログラムでは機能しません。paramparamIgnorePrintAreas
を 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();
}
}