Excel File Conversion
Excel to PDF with advanced options
The following example demonstrates setting worksheet level options using the DocumentParsing event of the ExcelConverter class. The initial ExcelConversionOptions class is set with a page size of A4 and later the page size is being changed to Letter for a specific worksheet 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