PC Review


Reply
Thread Tools Rate Thread

Convert xls to pdf

 
 
Avishay Ben-Zvi
Guest
Posts: n/a
 
      17th Jun 2008
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
 
Reply With Quote
 
 
 
 
Ron de Bruin
Guest
Posts: n/a
 
      17th Jun 2008
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" <(E-Mail Removed)> wrote in message news:F16B0E7F-981F-47F3-BA8E-(E-Mail Removed)...
> 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


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert Columns of Sensitive Information, and then convert back... =?Utf-8?B?V2lsbGlhbSBFbGVyZGluZw==?= Microsoft Excel Programming 1 12th Oct 2006 09:37 PM
IsNumeric: Convert.ToInt32 vs. Convert.ToInt64 sck10 Microsoft ASP .NET 4 3rd Sep 2006 10:40 PM
Convert file to binary, send it over the network, and convert it b =?Utf-8?B?Q2hld2ll?= Microsoft Dot NET 0 9th Sep 2005 06:04 PM
Convert file to binary, send it over the network, and convert it b =?Utf-8?B?Q2hld2ll?= Microsoft Dot NET Framework 1 9th Sep 2005 06:01 PM
convert decimal number to time : convert 1,59 (minutes, dec) to m =?Utf-8?B?YWdlbmRhOTUzMw==?= Microsoft Excel Misc 8 20th Jan 2005 10:24 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:25 AM.