ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Convert xls to pdf (https://www.excelbanter.com/excel-programming/412731-convert-xls-pdf.html)

Avishay Ben-Zvi

Convert xls to pdf
 
Im 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(paramSourceBookPat h,
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(paramExportForma t,
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

Ron de Bruin

Convert xls to pdf
 
Never used code like yours but take a look here
http://www.rondebruin.nl/pdf.htm

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Avishay Ben-Zvi" wrote in message ...
Im 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(paramSourceBookPat h,
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(paramExportForma t,
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




All times are GMT +1. The time now is 01:08 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com