Converting excel with multiple pages into PDF and PPT

Dear Team,

I’m trying to create the excel using Aspose.cells 8.7.0 jar file. My excel have multiple pages with tabular format chart. How we can convert it into PDF and PPT with multiple pages at run time. Is it possible to get the last cell of every page?

Could you please help regarding this.

Thanks
Prabu R

Hi,


Thanks for your query.

Aspose.Cells does support to convert Excel workbook into PDF file format. The rendering to PDF is same as built in MS Excel renderer, Aspose.Cells renders pages as the pages (for different worksheets in the spreadsheet) are shown in MS Excel when you take the print preview in it manually. Please see the document on how to convert Excel file to PDF file format:

And regarding find out last cell of each page or page area, see the sample code below for your reference (you may add/update the code segment for your needs), the code is written in .NET (C#) but you may easily convert it to JAVA code using the relevant Aspose.Cells for Java APIs:
e.g
Sample code:

Worksheet worksheet = workbook.Worksheets[0];

ImageOrPrintOptions printoption = new ImageOrPrintOptions();
printoption.PrintingPage = PrintingPageType.Default;
SheetRender sr = new SheetRender(worksheet, printoption);
int pageCount = sr.PageCount;
Console.WriteLine(pageCount.ToString());

CellArea[] area = worksheet.GetPrintingPageBreaks(printoption);
Console.WriteLine(area.Length.ToString());

for (int i = 0; i < area.Length; i++)
{

//Get the page rows of each area.
int strow = area[i].StartRow;
int stcol = area[i].StartColumn;

int numrows = area[i].EndRow - strow;
int numcols = area[i].EndColumn - stcol;

Console.WriteLine("Page " + (i + 1).ToString() + " starts at: " + CellsHelper.CellIndexToName(strow, stcol));



}

Furthermore, Aspose.Cells does not support to render to PPT file format (it is out of scope) as it is a spreadsheet management library rather than Powerpoint presentation library.

Thank you.


Dear Amjad Sahi,

Thanks for your solution.

I’m trying to convert the excel with multiple pages into PDF and PPT. For single page excel it’s working fine and able to create pdf and ppt perfectly. If I have multiple pages, I’m getting the multiple pages pdf without header row. To include the header row, I have included the below code.

Worksheet worksheet = workbook.getWorksheets().get(0);
PageSetup pageSetup = worksheet.getPageSetup();
PdfSaveOptions saveOptions = new PdfSaveOptions(com.aspose.cells.SaveFormat.PDF);
saveOptions.setAllColumnsInOnePagePerSheet(true);
saveOptions.setOnePagePerSheet(false);
saveOptions.setCreatedTime(DateTime.getNow());
pageSetup.setPrintTitleRows("$6:$6");

But not able to get the header row in every page. Could you please guide me to get the header row in every pages.

Also how to get the multiple slides, when we have more number of pages in excel, while creating ppt from excel.

Thanks
Prabu R

Hi Prabu,

prabu759101:



I'm trying to convert the excel with multiple pages into PDF and PPT. For single page excel it's working fine and able to create pdf and ppt perfectly. If I have multiple pages, I'm getting the multiple pages pdf without header row. To include the header row, I have included the below code.

Worksheet worksheet = workbook.getWorksheets().get(0);
PageSetup pageSetup = worksheet.getPageSetup();
PdfSaveOptions saveOptions = new PdfSaveOptions(com.aspose.cells.SaveFormat.PDF);
saveOptions.setAllColumnsInOnePagePerSheet(true);
saveOptions.setOnePagePerSheet(false);
saveOptions.setCreatedTime(DateTime.getNow());
pageSetup.setPrintTitleRows("$6:$6");

But not able to get the header row in every page. Could you please guide me to get the header row in every pages.

Could you provide us your template Excel file used in your code segment, we will check it soon. By the way, could you move the following line of code:
pageSetup.setPrintTitleRows("$6:$6");
before the line of code:
PdfSaveOptions saveOptions = new PdfSaveOptions(com.aspose.cells.SaveFormat.PDF);

if it works fine.

prabu759101:

Also how to get the multiple slides, when we have more number of pages in excel, while creating ppt from excel.

As I said earlier, Excel to PPT is not supported by Aspose.Cells, it is out of scope/context. Aspose.Pdf does support to convert PDF to PPT rendering, so you may use Aspose.Cells to convert Excel workbook to PDF and then use Aspose.PDF to convert the generated PDF (by Aspose.Cells) to PPT file format. If you find any issue with the rendering, do contact Aspose.Pdf team by posting your issue with details in Aspose.Pdf forum, they will help you soon there.

Thank you.

Dear Amjad Sahi,

I have moved the code as you have said. But it’s not working.
Herewith I have attached the template for your reference. Could you please provide the possible solution for this.

Regards
Prabu R

Hi,


Thanks for the template file.

I have evaluated your scenario/ case a bit. I have found the root cause of your issue. Actually the following line is the culprit line:
Worksheet worksheet = workbook.getWorksheets().get(0);

If you could check your Excel file, there is a hidden worksheet named “Lego 2.0” at index “0”, so you are actually setting the configurations/ settings for this sheet. Your Chart sheet is not set at all. Please change your line of code:
i.e.,
Worksheet worksheet = workbook.getWorksheets().get(0);

to:
Worksheet worksheet = workbook.getWorksheets().get(“Chart”);

it would work fine.

I have tested using your template file and following sample code to get expected results:
e.g
Sample code:

Workbook workbook = new Workbook(“Header+row+needed+for+every+pages.xlsx”);
Worksheet worksheet = workbook.getWorksheets().get(“Chart”);
PageSetup pageSetup = worksheet.getPageSetup();
pageSetup.setPrintTitleRows("$6:$6");
PdfSaveOptions saveOptions = new PdfSaveOptions(com.aspose.cells.SaveFormat.PDF);
saveOptions.setAllColumnsInOnePagePerSheet(true);
saveOptions.setOnePagePerSheet(false);
saveOptions.setCreatedTime(DateTime.getNow());

workbook.save(“out1.pdf”, saveOptions);

Let us know if you still have any issue.

Thank you.

Thanks a lot Amjad Sahi!!!

Now it’s working fine. Thank you for your quick response.

Regards
Prabu R

Hi,


Good to know that your issue is sorted out now. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.

Thank you.

Hi Amjad Sahi,

Thank you for your help.
I have achieved to set the title rows in every page.

My new requirement:
If I don’t want to set the title rows to a particular page, then how can I achieve it. In my case, the footer may be in new page. At that time, I don’t want to set the title rows.

For better understanding, please refer the attachment. Could you please guide us to resolve this issue.

Regards
Prabu R

Hi,


Thanks for the sample files and sharing the details.

How could you accomplish your task (without using “Rows to repeat at top” option) in MS Excel manually? Aspose.Cells follows MS Excel specifications and standards when rendering Excel to PDF file format, Aspose.Cells will render Excel worksheets to PDF as these are displayed when taking the print previews in MS Excel. I could not find any other way to accomplish your desired task without setting the repeating title rows. If you find any other way in MS Excel, kindly create a file with your desired settings (without using “Rows to repeat at top” option), provide complete steps details, save the file and post us here, we will check it soon.

Thank you.