setRecalculateBeforeSave() does not work for PDF

workbook.getSettings().setRecalculateBeforeSave(true) is not effective when workbook is saved as PDF.

I need to add an explicit workbook.calculateFormula() before saving.

Hi,


Thanks for your query.

Well, I think you may try to use PdfSaveOptions.setCalculateFormula() method, it will suit your needs:
e.g
Sample code:


PdfSaveOptions pdfOptions = new PdfSaveOptions(SaveFormat.PDF);
// Calculate formulas before saving to PDF.
pdfOptions.setCalculateFormula(true);
workbook.save(outputPdfFile, pdfOptions);

Hope, this helps a bit.

Thank you.

Both solutions work but it does not prevent ‘setRecalculateBeforeSave’ from not workink as attended.

Hi,

Well, the RecalculateBeforeSave option might be useful if you save the workbook to Excel (XLS, XLSX etc.) formats. So, for saving to PDF document, it is not a big deal to use either Workbook.calculateFormula() method or my suggested code segment.

Thank you.