Workbook workbook = new Workbook("Book1.xlsx");
int activeSheetIndex = workbook.Worksheets.ActiveSheetIndex;
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
//set active sheet index to sheet set.
pdfSaveOptions.SheetSet = new SheetSet(new int[] { activeSheetIndex });
workbook.Save("output.pdf", pdfSaveOptions);
Thank you for your help. Can you please confirm additional question below from the customer?
“It appears that this sample demonstrates how to convert files to PDF by specifying the order of the sheets. Do you happen to have a sample code that demonstrates how to specify sheet names and convert them to PDF?”
@ThomasMBK,
You can get the index according to the name of the sheet. Please refer to the following codes:
Workbook workbook = new Workbook("Book1.xlsx");
WorksheetCollection sheets = workbook.Worksheets;
//If you want to export the contents of the following three sheets
string[] sheetNames = {"Sheet1", "Sheet3", "Sheet5"};
int[] sheetIndexes = new int[3];
int index = 0;
foreach(string sheetName in sheetNames)
{
sheetIndexes[index++] = sheets[sheetName].Index;
}
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
//set sheet indexes to sheet set.
pdfSaveOptions.SheetSet = new SheetSet(sheetIndexes);
workbook.Save("output.pdf", pdfSaveOptions);