Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default 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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
can the "convert" function in excel convert to UK gallons? JR Excel Discussion (Misc queries) 2 April 24th 08 04:55 PM
Convert Columns of Sensitive Information, and then convert back... William Elerding Excel Programming 1 October 12th 06 09:37 PM
convert decimal number to time : convert 1,59 (minutes, dec) to m agenda9533 Excel Discussion (Misc queries) 8 January 20th 05 10:24 PM
Convert Time...!convert tenths of a second Pape Excel Discussion (Misc queries) 2 December 16th 04 10:17 AM


All times are GMT +1. The time now is 02:34 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"