We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Fails to convert huge Excel files to PDF format

Hello,

Our application use Aspose.Pdf (Ver 9.0.0.0) for convert Excel reports to PDF format.

based on report templates.


It fails when we are trying to convert Excel files that contains more than 12 columns.

It converts only the first 12 columns, rest of the columns are disappear.


We use the following code for convert:


public bool ConvertExcelToPDF(String fileName,bool bOpenIt)

{

if (!FileExist(fileName))

return false;


// Specify the pdf file path.

String pdfFile = fileName.Replace(Path.GetExtension(fileName),PDF_EXT);


//Create a new Workbook.

Workbook wb = null;

try

{

//Open the template excel file

wb = new Workbook(fileName);


foreach (Worksheet ws in wb.Worksheets)

{

ws.PageSetup.Orientation = PageOrientationType.Portrait;

}


// Enable suports excel formulas

wb.CalculateFormula();


try

{

//Save as pdf file.

wb.Save(pdfFile, Aspose.Cells.SaveFormat.Pdf);

}

catch (Exception e)

{

return error(e.Message);

}


return bOpenIt ? OpenPDF(pdfFile) : true;

}



Excel& PDF files are attachced


Thanks,



Hi Yoel,


Thank you for contacting Aspose support.

We believe you meant to specify the Aspose.Cells API version instead of Aspose.Pdf because your provided code snippet is using Aspose.Cells for .NET API.

Anyway, we have evaluated your presented scenario on our end, and we believe the PDF file generated on your end is correct according to the print area specified in the provided spreadsheet. Please check the attached snapshot for your reference. You will notice that the columns Q, R, S & U are outside the printable area. You may avoid this situation by explicitly specifying the PageSetup.PrintArea property as demonstrated below.

C#

Workbook book = new Workbook(“D:/temp/Project1-Detailed Engineering_MultiCurr1.xlsx”);
Worksheet sheet = book.Worksheets[0];
sheet.PageSetup.Orientation = PageOrientationType.Portrait;
sheet.PageSetup.PrintArea = “A1:U30”;
book.CalculateFormula();
book.Save(“D:/temp/output.pdf”, SaveFormat.Pdf);

Hello,

we are using both Aspose.Cells & Aspose.pdf.


I believe this line suppose to solve the issue.

sheet.PageSetup.PrintArea = "A1:U30";

I know how many columns will be in the output file.
So, column 'U' is enough for me. however, I don't know how many lines going to be in the output file.


Thanks,

Hi Yoel,


Good to know that the provided solution helped in your scenario. In order to get the maximum number of data rows, please use the Cells.MaxDataRow property as demonstrated below.

C#

Cells cells = sheet.Cells;
int maxRow = cells.MaxDataRow;