Export selected area to PDF and Slides in ASPOSE CELLS - JAVA

Kindly help me on this urgently…


Export selected area to PDF and Slides in ASPOSE CELLS in JAVA

Hi,

Well, you need to specify/ set your desired printable area (that should cover your desired area in the worksheet) using PageSetup options before rendering to PDF file format, see the document on setting printing options:

Page Setup and Printing Options

e.g

Sample code:

Workbook workbook = new Workbook(strFileName);
Worksheet worksheet = workbook.getWorksheets().get(0);
worksheet.getPageSetup().setPrintArea(“A1:F10”);
//Save the workbook into PDF
workbook.save(“output1.pdf”);

Thank you.

Thanks for your reply. Your info is crystal clear. I will work on it and get back to you.

Hi,


As per your code, I am able to get the PDF as expected. But I have another issue

For example, I have a chart in the cell G1:I10. How to export Chart to PDF.

Please help me out.

Hi,


Thank you for writing back.

I have tested your recently shared scenario. If your defined print area range contains a chart, it will be exported to PDF just fine. Please try it on your side, and in case you are not getting the desired results then please share your sample spreadsheet so we could provide you the exact code for you requirement.

Team,


Here I attached my code and sample.xls sheet for your reference. In that sheet, I need to make PDF only to this area A1:AE41 and it has to be in the single pdf.

Regards,
Venki

Hi Venki,


Thank you for sharing your sample spreadsheet and code.

Please use the following piece of code to render only the area range “A1:AE41” to single page of the PDF file.

Java

Workbook workbook = new Workbook(“D:/sample.xls”);
Worksheet worksheet = workbook.getWorksheets().get(0);
worksheet.getPageSetup().setPrintArea(“A1:AE41”);
worksheet.autoFitRows();
PdfSaveOptions option = new PdfSaveOptions();
option.setOnePagePerSheet(true);
workbook.save(“D:/output.pdf”, option);

Please note, the above code snippet is reading the spreadsheet from the disc. In case you wish to first create the chart and then render without first saving the spreadsheet to disc then please call the Chart.calculate method before rendering the chart on PDF format.

Thanks for your code and it is not working as expected to me… I am using ASPOSE CELL 8.3.1… Am I using the right version ?

Hi Venki,


You haven’t shared the PDF generated on your end therefore we cannot comment if you are getting the correct results with v8.3.2. However, we are performing all tests while using the latest version of Aspose.Cells for Java (Latest Version) and the results attached to our previous response are correct according the code snippet provided in same post. Please give a try to the latest version and if you think the results are not expected then please share the results from your end along with little details on how do you expect the results to be.