I’m attempting to take a single sheet from a workbook and convert it to pdf. The sheet has a chart. The data for the chart is on a different sheet that I do not want included in the pdf. My approach is to copy the sheet that I want to a new workbook and then save the workbook as a PDF. However, the data on the chart is not included in the pdf with this approach. I confirmed that the chart was still rendered when using v. 8.3.0.4. I am using version 17.3.0.
I’m attaching the sample excel sheet that I can use to reproduce the problem.
Here is my code:
<pre style=“background-color: rgb(255, 255, 255); font-family: “Courier New”; font-size: 9pt;”>Path path = Paths.get(“Model.xlsx”);
Workbook sourceWorkbook = new Workbook(Files.newInputStream(path));
Worksheet sourceSheet = sourceWorkbook.getWorksheets().get(“Valuation”);
Workbook workbookToPDF = new Workbook();
workbookToPDF.getWorksheets().get(0).copy(sourceSheet);
PdfSaveOptions saveOptions = new PdfSaveOptions(SaveFormat.PDF);
String pdfPath = “Test.pdf”;
workbookToPDF.save(pdfPath, saveOptions);
Workbook sourceWorkbook = new Workbook(Files.newInputStream(path));
Worksheet sourceSheet = sourceWorkbook.getWorksheets().get(“Valuation”);
Workbook workbookToPDF = new Workbook();
workbookToPDF.getWorksheets().get(0).copy(sourceSheet);
PdfSaveOptions saveOptions = new PdfSaveOptions(SaveFormat.PDF);
String pdfPath = “Test.pdf”;
workbookToPDF.save(pdfPath, saveOptions);
I consider this a defect since it worked in a previous versioon; I’m hoping for a work around.
Regards