BoldDeskWe are launching BoldDesk on Product Hunt soon. Learn more & follow us.
Hi,
We are using SyncFusion to convert Excel files to PDF's however we have an issue with the date format applied to the cells, in Excel we have it in DD/MM/YYY however when converted to PDF it is applying M/D/YYY
Is there a setting to control this?
Thanks, Andy
Hi Andy,
Kindly share the input Excel document and confirm us the Syncfusion XlsIO version you are using at your end, to investigate the query further.
Regards,
Keerthi.
Hi Keerthi,
Attached is a simple sample document. When we convert the document we get the below, where the dateformat is changed.
The XlsIO version from the dll is 20.2200.0.48
Thanks, Andy
Thanks for sharing the file as requested, Andy.
DateTime format gets changed based on the system culture. If you wish to maintain the format irrespective of the system culture, we suggest you to set the required number format, before converting to PDF. Please find the code snippet below.
Code Snippet:
using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; FileStream excelStream = new FileStream("Book1.xlsx", FileMode.Open, FileAccess.Read); IWorkbook workbook = application.Workbooks.Open(excelStream);
IStyle style = workbook.Styles.Add("Style"); style.NumberFormat = "DD/MM/YYYY";
workbook.Worksheets[0].SetDefaultColumnStyle(1, style);
//Initialize XlsIO renderer. XlsIORenderer renderer = new XlsIORenderer();
//Convert Excel document into PDF document PdfDocument pdfDocument = renderer.ConvertToPDF(workbook);
MemoryStream stream = new MemoryStream(); pdfDocument.Save(stream); //Set the position as '0'. stream.Position = 0; //Download the PDF document in the browser. FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/pdf"); fileStreamResult.FileDownloadName = "Sample.pdf"; return fileStreamResult; } |
Kindly try and let us know if this helps.
Regards,
Keerthi.