We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to convert only specific excel worksheets to PDF?

Hi,

We are using Aspose.Cells SDK to convert excel files to PDF. Prior to saving it as PDF, we are also hiding unnecessary worksheets (These excel workbooks have multiple worksheets with a few hidden and few visible)
Sometimes, the users accidently unhide some of the hidden one’s which get converted to PDF. In order to prevent it, is there a way to convert only the worksheets that start with a ‘book_’ to PDF? Please let me know how can I achieve this?

Any help is greatly appreciated. Thank you in advance.

Regards
SLS

@s2205
Please try the following codes:
Workbook workbook = new Workbook(dir + “test.xlsx”);
foreach (Worksheet sheet in workbook.Worksheets.Where(worksheet => !worksheet.Name.StartsWith(“book_”)))
{
sheet.IsVisible = false;
}
workbook.Save(dir + “dest.pdf”);

1 Like

Thank you for your response @simon.zhao. That worked :slight_smile:

@s2205,

Good to know that the suggested code segment works for your needs. Feel free to contact us any time if you need further help or have some other queries or issue, we will be happy to assist you soon.