Excel File Conversion

DynamicPDF Converter supports Excel file conversion. The following example illustrates converting an Excel worksheet with advanced conversion options.

Excel to PDF with advanced options

In this example, you first set the worksheet level options using the DocumentParsing event of the ExcelConverter class. The initial ExcelConversionOptions class is set with a page size of A4. The page size is then changed to Letter for the specific worksheet named "Sheet 1" in the event.

 private static void ExcelDemo(string inPath, string outPath)
 {
     ExcelConversionOptions excelOptions = new ExcelConversionOptions(ExcelPageSize.A4, PageOrientation.Portrait, 36);
     ExcelConverter excelConverter = new ExcelConverter(inPath, excelOptions);
     excelConverter.DocumentParsing += excelConverter_DocumentParsing;
     excelConverter.Convert(outPath);
 }  
                        
 static void excelConverter_DocumentParsing(object sender, ExcelDocumentParsingEventArgs excelDocumentParsing)
 {
     foreach (var sheet in excelDocumentParsing.Worksheets)
     {
         if (sheet.SheetName != "Sheet 1")
         {
             sheet.ConversionOptions.PageSize = ExcelPageSize.Letter;
         }
     }
 }
 Private Sub ExcelDemo(ByVal inPath As String, ByVal outPath As String)
         Dim excelOptions As ExcelConversionOptions = New ExcelConversionOptions(ExcelPageSize.A4, PageOrientation.Portrait, 40)
         Dim excelConverter As ExcelConverter = New ExcelConverter(inPath, excelOptions)
         AddHandler excelConverter.DocumentParsing, AddressOf excelConverter_DocumentParsing
         excelConverter.Convert(outPath)
 End Sub
                        
 Private Sub excelConverter_DocumentParsing(sender As Object, ExcelDocumentParsing As ExcelDocumentParsingEventArgs)
         For Each sheet In ExcelDocumentParsing.Worksheets
             If sheet.SheetName = "Sheet 1" Then
                 sheet.ConversionOptions.PageSize = ExcelPageSize.Letter
             End If
         Next
 End Sub

In this topic