[Solved] - bestway to convert multiple sheet to one pdf file?

Hi,
How do I pick a few random sheets and put them in a pdf file?
Thanks you!

3 Replies 1 reply marked as answer

KK Konduru Keerthi Konduru Ravichandra Raju Syncfusion Team June 4, 2020 11:17 AM UTC

Hi Khanh Dang, 

Greetings from Syncfusion. 

We have prepared simple sample to meeting your requirement and the same can be downloaded from the following link. 


Please find the code snippet we have used in the above sample. 

Code Snippet: 

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"); 

Kindly try and let us know if this helps. 

Regards, 
Keerthi. 


Marked as answer

TG The GridLock June 4, 2020 11:36 AM UTC

Hi Keerthi,
This is exactly what I need!


KK Konduru Keerthi Konduru Ravichandra Raju Syncfusion Team June 4, 2020 12:53 PM UTC

Hi Khanh Dang, 
  
We are glad that the provided solution helped you. 
  
Regards, 
Keerthi. 


Loader.
Up arrow icon