I'm using C# code to convert an Excel file to a PDF. Everything works fine except the date formats, which are incorrect in the PDF, even though they are correct in the Excel file.
| 17h00 |
In pdf format : 17h0 or some time i have #name
Thank you for you replay
Hi
Aitbouhou Adam,
We have attempted to
convert the Excel file to PDF, and the issue appears to be resolved in the
latest NuGet version. We kindly request you to update the NuGet packages to the
latest version and check if the issue is resolved. If the issue still persists,
we recommend sharing a sample or code snippet that reproduces the problem. This
will help us to validate the problem and provide a solution at the earliest.
Regards,
Yaavann.
Hello
I used version 27.2.4 but I still have the same problem
Many thanks
Hi Aitbouhou Adam,
We
were unable to reproduce the issue on our end. We have shared the sample we
tested, along with the converted PDF document for your reference. Kindly review
it. We recommend modifying the sample or providing a sample that reproduces the
issue, This will help us to validate the issue and provide you a solution at
the earliest.
Regards,
Yaavann.
Hello
Thank you for your replay.
Your code works fine for me,
here is the code I use, and when I commented out this line // CalculateFormulaForPdf(wb);
that works
System.Globalization.CultureInfo.CurrentCulture =
System.Globalization.CultureInfo.GetCultureInfo("fr-FR");
XlsIORendererSettings settings = new XlsIORendererSettings
{
EmbedFonts = true
};
using (ExcelEngine excelE = new ExcelEngine())
{
IApplication application = excelE.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
//Initialize XlsIO renderer.
XlsIORenderer renderer = new XlsIORenderer();
using (FileStream excelStream = new FileStream("C:\\Data\\input.xlsx", FileMode.Open, FileAccess.Read))
{
IWorkbook wb = application.Workbooks.Open(excelStream);
CalculateFormulaForPdf(wb);
//Convert Excel document with charts into PDF document
using (PdfDocument pdfDocument = renderer.ConvertToPDF(wb, settings))
{
using (Stream s = new FileStream("C:\\Data\\output.pdf", FileMode.Create, FileAccess.ReadWrite))
{
pdfDocument.Save(s);
}
}
}
}
/****/
public static void CalculateFormulaForPdf(IWorkbook workbook)
{
foreach (var sheet in workbook.Worksheets)
{
List<IRange> lstCells = sheet.UsedCells.Where(x => x.HasFormula).ToList();
sheet.EnableSheetCalculations();
foreach (var cell in lstCells)
{
try
{
cell.Value = cell.CalculatedValue;
}
catch
{
// wrong formula inside
}
}
sheet.DisableSheetCalculations();
}
}
Hi Aitbouhou Adam,
We were able to reproduce the reported issue and are currently validating it. We will share the validation details on December 4, 2024.
Regards,
Atchaya S.
Hi Aitbouhou Adam,
We have reviewed the
reported issue, and it can be resolved by setting the GetValueFromArgPreserveLeadingZeros property to true. This will
address the issue at the sample level. Kindly please refer to the attached code
snippet and UG link shared below.
For more information, please refer to the following resources in our User Guide documentation:
|
public
static void CalculateFormulaForPdf(IWorkbook workbook)
foreach (var cell in
lstCells) |
Regards,
Yaavann.