When saving the attached document applicant.zip (252.6 KB)
as pdf, the ‘%’ sign shows by wrong cells (and sometimes does not shows where required).
Thanks for using Aspose APIs.
We have converted your Excel file into Pdf using the following code. Please highlight the issues inside it by adding comments inside the Pdf or provide your own screenshots highlighting the issue.
Download Link:
out.pdf (1.1 MB)
C#
Workbook wb = new Workbook("applicant.xlsx");
wb.Save("out.pdf");
Please see my comment on page 2. There are several instances, but the problem is the same.
In fact, some of the non-percent formatted cells come out as ‘%’.
applicant_marked.zip (57.2 KB)
Thanks for the sample PDF file.
Well, you got to refresh PivotTable and calculate its data before rendering to PDF. Please see the following sample code for your reference:
e.g
Sample code:
Workbook wb = new Workbook("e:\\test2\\applicant.xlsx");
foreach (Worksheet ws in wb.Worksheets)
{
foreach (PivotTable pt in ws.PivotTables)
{
try { pt.RefreshData(); }
catch { }
try { pt.CalculateData(); }
catch { }
try { pt.CalculateRange(); }
catch { }
}
}
wb.Save("e:\\test2\\out1.pdf");
Let us know if you still find any issue.
Thank you.
Thank you.
This works fine now.
Out application needs to read an existing document, then save it as a pdf document.
Are there any other elements we need to Refresh/Calculate before saving?
Good to know that your issue is sorted out.
Please note:
- if there are PivotTables in the worksheet(s), then you need to refresh and calculate data for the PivotTables.
- If there are formulas in the spreadsheet, you need to calculate formulas using Workbook.CalculateFormula() before rendering to PDF file format.
Thank you.
How do I iterate all formulas in a worksheet?
There can be different approaches to iterate through formula cells, a few of them can be as following (please see the code segments for your reference):
e.g
Sample code:
-
string filePath = @“e:\test\Book1.xlsx”;
//Load a source workbook Workbook wb = new Workbook(filePath); int cnt = 0; string cellname = null; string ftext = null; //you may define some arrays or list //Iterate all worksheets for (int i = 0; i < wb.Worksheets.Count; i++) { Cells cells = wb.Worksheets[i].Cells; //iterate all the cells. for (IEnumerator ie = cells.GetEnumerator(); ie.MoveNext(); ) { Cell cell = (Cell)ie.Current; if (cell.IsFormula) { cellname = cell.Name; ftext = cell.Formula; //.......... //Your code goes here. //.............. cnt++; }//if }//for }//for
-
Cells cells = worksheet.Cells;
//Loop through each cell in the sheet which is initialized only to save time.
foreach (Cell cell in cells)
{if (cell.IsFormula) { string cellVal = cell.Formula; cell.PutValue(cellVal); } }
Hope, this helps a bit.
Thank you.
Thanks.
You may close this case.