I have an issue when exporting an Excel file to pdf that do not keep the same format.
I must print a document in two different formats, Excel & PDF, and I have also a template (xlsx file) provided by a third-party password protected (I can’t edit template).
The program fulfils the template with data from the database, setting values in its corresponding cell and I get the file in Excel format that looks like this: File1 hosted at ImgBB — ImgBB
public static byte[] ExcelToPdf(string name)
{
try
{
var blob = StorageHelper.GetBlob(“asposepdf”, name);
Stream data = blob.OpenRead();
data.Position = 0;
using (MemoryStream dstStream = new MemoryStream())
{
var s = new Workbook();
s.Save(dstStream, SaveFormat.Pdf);
return dstStream.ToArray();
}
}
catch (Exception ex) …
If I open the Excel file before converting to pdf It is fine, it’s just when exporting to pdf.
I’m using Aspose.Cells 24.2.0 version.
I am sorry but I could not reproduce the issue as I tested your scenario/case using your source file. I used the following simplest lines of code to just load the XLSX file and save it as PDF via Aspose.Cells for .NET APIs. The output PDF is fine tuned and same as the input Excel file.
e.g. Sample code:
Workbook workbook = new Workbook("g:\\test2\\PoS Support.xlsx");
workbook.Save("g:\\test2\\out1.pdf");
Please find attached the output PDF file for your reference. out1.pdf (125.5 KB)
Please debug your sample project/code and resource files and fix your issue by yourself on your end. In case, you still think it is an issue with Aspose.Cells for .NET APIs, please provide a standalone console application (source code without compilation errors) or runnable sample code with relevant resource files to reproduce the issue on our end. We will check it soon.
Hi thank you for your support. Long time since my post, but I was sick and couldn’t reply you. Sorry about that.
I have created a small project where I can reproduce the issue. You can find it here https://github.com/random-71/Excel2PDF (let me know if any issue, I’m not used to using Github)
Thanks for publishing the project on Github repos.
I used your exact sample code (of Github repos.) with your template XLSX file to generate two PDF files and both are fine tuned. Please find attached the output PDF files for your reference. kk.pdf (126.5 KB) EndFile.pdf (126.5 KB)
Could you please share your output PDFs? We will check your issue further.
I think it depends on the excel file. The one in the repositiry works because the Excel has been locally saved. I’ve uploaded the right Excel to the repositiry. I hope you can see the same result than me now.
@juanc
With the updated template file, we can reproduce the issue. It is caused by those formulas that use XOR function. Currently this function is not supported by Aspose.Cells yet.
We have opened the following new ticket(s) in our internal issue tracking system to support this new function and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): CELLSNET-55475
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
Thank you for your support, but I’ve managed to replaced the XOR function in the Excel template and still same behavior. Could you please take a look? I’ve uploaded last template in Git’s project.
@juanc
Thank you for your feedback. We will further investigate the issue and notify you immediately of any updates.
Also, would you like to provide the sample file after deleting the XOR function? We will check it soon.
We tested with your updated XLSX file you uploaded/replaced @ Github repos. and found the issue is still there. Please spare us little time to evaluate it in details. We will get back to you soon.
I do not understand, this is the original cell where I have replaced the XOR formula by this one: =IF(AND(AA69;NOT(AB69));TRUE;IF(AND(AB69;NOT(AA69));TRUE;FALSE))
I think you are talking about the cell ‘PoS 1’!AC69. Yes, it contains no XOR function as you said. However, the worksheet ‘PoS 1’ is not the first sheet in the workbook. And the cell I am talking about is ‘PoS form’!AC69, the worksheet ‘PoS form’ is the first one but it is hidden in your template file.
@juanc
We are pleased to inform you that we have supported the calculation of XOR function(CELLSNET-55475). The fix will be included in our upcoming release (Aspose.Cells v24.5) that we plan to release in the second week of May 2024. You will be notified when the next version is released.
Here is the resultant pdf file generated with the fix for your reference. Please check whether it is ok for you: res.pdf (127.1 KB).
And the code example:
Workbook wb = new Workbook("PoS Support.xlsx");
wb.CalculateFormula();
wb.Save("res.xlsx");