2

I have an excel file which has 10 sheets. We can use below to export the entire excel file to one pdf file.

ExportAsFixedFormat(Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF, outputPath, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

Is it possible to export each sheet as a pdf file? So totally, I have 10 pdf files?

WorkSheet.SaveAs can save the sheet, but it does not export to pdf.

Thanks

urlreader
  • 6,319
  • 7
  • 57
  • 91

1 Answers1

2

I think you may need to iterate the Sheets(spreadsheets & chart sheets)/Worksheets(spreadsheets only) and export each sheet individually.

// add using Microsoft.Office.Interop.Excel;
// wb - workbook reference
foreach (Worksheet workSht in wb.Sheets)
{
    if (workSht.UsedRange.Cells.Count > 0)
    {
        workSht.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, 
                                                      outputPath + workSht.Name);
     }
 }
  • thanks. it works. I did not know it is WorkSheet instead of Sheet. That's why I could not find ExportAsFixedFormat for the sheet. – urlreader Jul 04 '14 at 19:11