How to improve memory & performance while print & export the Spreadsheet?
We can improve the performance and memory consumption while exporting to PDF document in WPF Spreadsheet, the cell “G4” is calculated which contains another calculated formula that depends on another calculated formula and so on. Due to these recursive operations, stack value throws an exception while exporting the document to PDF.
This problem can be resolved in sample level by setting the maximum size of stack while exporting the workbook with new thread.
C#
private static void OnExecuteDirectPrint(object sender, ExecutedRoutedEventArgs args) { spreadsheetControl = args.Source as SfSpreadsheet; //Create the pdfviewer for load the document. PdfViewerControl pdfviewer = new PdfViewerControl(); // PdfDocumentViewer pdfstream = new MemoryStream(); var maxSize = 10000000; var thread = new Thread(PrintFromPdfViewer, maxSize); thread.Start(); thread.Join(); //Load the document to pdfviewer pdfviewer.Load(pdfstream); //Show the print dialog. pdfviewer.Print(true); }
You must set the AllowShortCircuitIFs and MaximumRecursiveCalls properties in threading while printing or exporting to PDF.
C#
private static void PrintFromPdfViewer() { spreadsheetControl.ActiveSheet.Workbook.Worksheets[0].EnableSheetCalculations(); spreadsheetControl.ActiveSheet.Workbook.Worksheets[0].CalcEngine.AllowShortCircuitIFs = true; spreadsheetControl.ActiveSheet.Workbook.Worksheets[0].CalcEngine.MaximumRecursiveCalls = 10000;
ExcelToPdfConverter converter = new ExcelToPdfConverter(spreadsheetControl.Workbook); //Intialize the PdfDocument PdfDocument pdfDoc = new PdfDocument();
//Intialize the ExcelToPdfConverter Settings ExcelToPdfConverterSettings settings = new ExcelToPdfConverterSettings(); settings.LayoutOptions = LayoutOptions.NoScaling;
//Assign the PdfDocument to the templateDocument property of ExcelToPdfConverterSettings settings.TemplateDocument = pdfDoc; settings.DisplayGridLines = GridLinesDisplayStyle.Invisible;
//Convert Excel Document into PDF document pdfDoc = converter.Convert(settings);
//Save the PDF file pdfDoc.Save(pdfstream); } |
Sample Link - WPF
Conclusion
I hope you enjoyed learning about how to improve memory & performance while print & export the Spreadsheet.
You can refer to our WPF Spreadsheet feature tour page to know about its other groundbreaking feature representations. You can also explore our WPF Spreadsheet documentation to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!