Convert xls to pdf

A

Avishay Ben-Zvi

I’m trying to use the code in attached the link:

http://msdn.microsoft.com/en-us/library/bb407651.aspx




Microsoft.Office.Interop.Excel.ApplicationClass excelApplication = new
Microsoft.Office.Interop.Excel.ApplicationClass();
Workbook excelWorkBook = null;

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 = true;
object paramFromPage = Type.Missing;
object paramToPage = Type.Missing;



try
{
// Open the source workbook.
excelWorkBook =
excelApplication.Workbooks.Open(paramSourceBookPath,
paramMissing, paramMissing, paramMissing, paramMissing,
paramMissing, paramMissing, paramMissing, paramMissing,
paramMissing, paramMissing, paramMissing, paramMissing,
paramMissing, paramMissing);




// Save it in the target format.
if (excelWorkBook != null)
excelWorkBook.ExportAsFixedFormat(paramExportFormat,
paramExportFilePath, paramExportQuality,
paramIncludeDocProps, paramIgnorePrintAreas,
paramFromPage,
paramToPage, paramOpenAfterPublish,
paramMissing);

}
catch (Exception exc)
{
// Respond to the error.

}
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();
}
It works fine except for the process that is created but not closed after
the operation is done.

What else is missing?

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top