Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Tue Feb 22, 2022 9:44 am

Hi,
I have problem with converting xls file to pdf when it comes to date format.
My short date format in Windows10 is yy/MM/dd e.g. Windows taskbar shows date 22/02/22.
Xls file contains cell with date format yy/MM/dd e.g. 22/02/15.
After converting file to pdf, pdf shows date in format M/dd/yyyy e.g. 2/15/2022,
so format is different in xls and pdf file.

I attached original xls file and converted pdf file.

This is the code I use for converting:
Code: Select all
Workbook workbook = new Workbook();
workbook.LoadFromFile(filePath);
workbook.ConverterSetting.SheetFitToPage = true;
workbook.SaveToFile(convertedToPdfFilePath, Spire.Xls.FileFormat.PDF);


I am using paid version Spire.Office for .NET 11.12.0.5420

I want to preserve formating of date format in pdf so date appears in same format as in original pdf.
Can you help?

Thanks
Attachments
SpireTest.zip
(12.67 KiB) Downloaded 98 times

filipfilipfilip
 
Posts: 45
Joined: Mon Jun 14, 2021 10:27 am

Tue Feb 22, 2022 10:09 am

Hello,

Thanks for your inquiry!

I download the file you provided, but the data shows like the following screenshot. And after converting, the PDF file is the same as the XLS file.
compare.png
compare.png (22.52 KiB) Viewed 763 times
\

Actually, the date format in the Excel is related to the region setting of your system. On my side, my region setting is Chinese,China, so the date value is shown as my region setting. I just recommend that you can use "Thread.CurrentThread.CurrentCulture = new CultureInfo("en-us")" to the region you wanted before you convert the Excel to PDF. If the format still has issue, please provide us with your system information (E.g. Win7, 64 bit) and region setting (E.g. China, Chinese). Thanks in advance.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Tue Feb 22, 2022 1:35 pm

Hi,
Attached is example from my computer, Windows 10, 64 bit, English (United States) region, short date format in Windows - yy/MM/dd.
Year is everyvery in format yy, but on pdf is yyyy.
Thanks
Attachments
Spire.jpg
Spire.jpg (128.36 KiB) Viewed 760 times

filipfilipfilip
 
Posts: 45
Joined: Mon Jun 14, 2021 10:27 am

Wed Feb 23, 2022 6:11 am

Hello,

Thanks for sharing more information!

I did reproduce the issue according to your region setting, and this issue has been logged it in our issue tracking system with the ticket SPIREXLS-3705 for further investigation.

We will let you know if there is any update. Sorry for the inconvenience caused.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Wed Mar 23, 2022 9:02 am

Hello,

Thanks for your patience!
Glad to inform you that we just released Spire.XLS Pack(Hotfix) Version:12.3.8 which fixes the issue with SPIREXLS-3705.
Please download and refer to the sample code for testing.
Website link: https://www.e-iceblue.com/Download/download-excel-for-net-now.html
Nuget link: https://www.nuget.org/packages/Spire.XLS/12.3.8
Code: Select all
Workbook workbook = new Workbook();
workbook.Version=ExcelVersion.Version2016;//add code
workbook.LoadFromFile(filePath);
workbook.ConverterSetting.SheetFitToPage = true;
workbook.SaveToFile(convertedToPdfFilePath, Spire.Xls.FileFormat.PDF);


Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1647
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.XLS