using(ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
//Open an Excel document
IWorkbook workbook = application.Workbooks.Open("../../Data/Sample.xlsx", ExcelOpenType.Automatic);
//Get the first worksheet
IWorksheet worksheet1 = workbook.Worksheets[0];
//Load the first worksheet into ExcelToPdfConverter
ExcelToPdfConverter converter1 = new ExcelToPdfConverter(worksheet1);
//Initailize PdfDocument
PdfDocument document = new PdfDocument();
//Initailize ExcelToPdfConverterSettings
ExcelToPdfConverterSettings settings = new ExcelToPdfConverterSettings();
//Set the PdfDocument to TemplateDocument in ExcelToPdfConverterSettings
settings.TemplateDocument = document;
//Convert the worksheet with settings
document = converter1.Convert(settings);
//Get the third worksheet
IWorksheet worksheet3 = workbook.Worksheets[2];
//Load the third worksheet into ExcelToPdfConverter
ExcelToPdfConverter converter2 = new ExcelToPdfConverter(worksheet3);
//Convert the worksheet with settings
document = converter2.Convert(settings);
//Save the PdfDocument
document.Save("ExcelToPDF_New.pdf");
System.Diagnostics.Process.Start("ExcelToPDF_New.pdf");
} |