I wrote a program that creates an excel file and at the end of that file, it creates a chart from that data.
Then I export that file to pdf via ExportAsFixedFormat method but it just exports that chart to pdf.
How can I export the whole page to pdf?
(I use Office 2007)
Thanks


Suthish NairRank #92 · 22.8K reputationPosted Oct 20, 2011, 9:14 AM EDT
Majid KamaliRank #6,453 · 266 reputationPosted Oct 20, 2011, 10:33 AM EDT
I want to create a pdf from an existing excel file.
Also I do not have enough time to learn iTextSharp.
Please help.
Javeed M ShaikhRank #839 · 2.7K reputationPosted Oct 20, 2011, 11:59 AM EDT
Please check if you are doing the same steps like below:
string paramSourceBookPath = @"C:\MyExcel.xlsx";
object paramMissing = Type.Missing;
string paramExportFilePath = @"C:\MyTestPdf.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 ex)
{
// 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();
}
Please do not forget to mark "Accepted Answer".
Majid KamaliRank #6,453 · 266 reputationPosted Oct 20, 2011, 9:09 PM EDT
I should activate a arbitrary cell before exporting to pdf. because chart must be unselected.
before my code, I used this:
(myWorkSeet.Cells[1,1] as Excel.Range).Activate();