Vlookups not working when saving excel files to PDF

Hello,

I am creating PDFs from excel templates. We have one worksheet that contains pricing data which is used on other worksheets. I programmatically open the pricing worksheet (pricelist) and insert the price in the appropriate cell. The vlookups are used to pull that data into the other worksheets.

I I save the workbook as an excel file it works great. I open the workbook and the data is populated appropriately.

If I save the workbook as a pdf the vlookups do not work. The pricing data is not populated. Below is a code snippet that demonstrates simply inserting one price and saving to pdf. I have attached the template.xslx file as well.

vartestWorkbook = new Workbook(@"C:\template.xlsx");

testWorkbook.Worksheets[

"pricelist"].Cells[1, 1].PutValue(10);

testWorkbook.Save(@"C:\test.pdf", SaveFormat.Pdf);

Hi,

Thanks for your posting and using Aspose.Cells for .NET.

Please use the following code. It works fine. You need to use the Workbook.CalculateFormula() method to get the correct results.

Please download and use the latest version:
Aspose.Cells
for .NET v7.3.1.3



I have attached the output pdf generated by the following code. Please also see the screenshot for your reference.

C#


string filePath = @“F:\Shak-Data-RW\Downloads\template.xlsx”;


var testWorkbook = new Workbook(filePath);


Worksheet worksheet = testWorkbook.Worksheets[“pricelist”];


worksheet.Cells[1, 1].PutValue(10);


testWorkbook.CalculateFormula();


testWorkbook.Save(@“test.pdf”, SaveFormat.Pdf);



Screenshot:

Hello,

Thank you for the quick response. That was the solution. It works perfectly now.

Hi,


Good to know that your issue is resolved following the suggestion by Shakeel Faiz.

Also, whenever you need to update or insert values into the cells, you will always need to call Workbook.CaculateFormula() method before rendering to PDF, so the formulas are calculated based on the updated/inserted values.

Thanks, and have a good time!