Can I exclude Hidden sheets when I convert excel to PDF in the Telerik.Windows.Documents.Spreadsheet library?

1 Answer 196 Views
PdfProcessing SpreadProcessing
Yudith
Top achievements
Rank 1
Veteran
Yudith asked on 14 Mar 2022, 04:26 AM

Hi Telerik,

I saw there is a property to exclude the hidden sheets here and here.

But, when I tried to see it in the code, I didn't find it.

I'm using version 2019.3.1021.

Is it not available on my version?

If yes, is there any workaround?

Thank you.

 

1 Answer, 1 is accepted

Sort by
1
Accepted
Svilen
Telerik team
answered on 14 Mar 2022, 12:59 PM

Hi, Yudith, 

Svilen here, I will be glad to help out with this question.

As noted in our PdfFormatProvider Settings article, the property responsible for this functionality is PdfExportSettings.IncludeHiddenSheets, which is set to false by default. We've added this property as a response to the request to skip hidden sheets, posted in this public feedback item - SpreadProcessing: Hidden sheets should not be exported to PDF. It is available for versions post 2021.3.1025.

Still, if you are unable to update, a workaround for this would be to create a copy of the workbook you wish to export, iterate through it and delete all hidden sheets before exporting. Here is a sample snippet code on how to do this:

Workbook exportCopy = workbook; //Create a copy solely for exporting. The original is not affected.

foreach (var sheet in exportCopy.Worksheets)
{
    if (sheet.Visibility == SheetVisibility.Hidden)
        exportCopy.Worksheets.Remove(sheet);
}

using (Stream output = new FileStream("PDF.pdf", FileMode.Create))
{
    pdfProvider.Export(exportCopy, output);
}

Please let me know if this helps.

Regards,
Svilen
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Yudith
Top achievements
Rank 1
Veteran
commented on 15 Mar 2022, 03:02 AM

Hi Svilen, It worked!

Thank you for the workaround.

Have a nice day!

Tags
PdfProcessing SpreadProcessing
Asked by
Yudith
Top achievements
Rank 1
Veteran
Answers by
Svilen
Telerik team
Share this question
or