Excel columns are scattered in PDF

Hi Team,


Iam trying to read data from Excel and convert it into PDF.
The data in excel is getting scattered (as per columns) in the converted PDF

string filePath = “~/Test File 2.xlsx”;

FileStream excelStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
FileStream pdfStream = new FileStream(filepath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
Workbook workbook = new Workbook(excelStream);

Aspose.Cells.PdfSaveOptions saveOptions = new Aspose.Cells.PdfSaveOptions(Aspose.Cells.SaveFormat.Pdf);
saveOptions.OnePagePerSheet = true;
saveOptions.AllColumnsInOnePagePerSheet = true;
workbook.Save(pdfStream, Aspose.Cells.SaveFormat.Pdf);

excelStream.Close();
pdfStream.Close();

Please let me know how to fix this issue.

Thanks in advance.


Hi,


Thanks for providing us some details and sample code.

Could you please provide us the template file “Test File 2.xlsx”, we will check your issue soon.

Thank you.

Hi Team,


Thanks for the prompt response.
Attached is the test file and the output file as well.

Hi,


Thanks for the template files.

There is an issue with your code, please change the line of code:
i.e.,
workbook.Save(pdfStream, Aspose.Cells.SaveFormat.Pdf);

to:
workbook.Save(pdfStream, saveOptions);

it would work fine.

Let us know if you still have any issue.

Thank you.

Thanks aton :slight_smile:

Its working now…
Appreciate your response…Thanks again !!

Hi,


Good to know that it works for your needs. 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.