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.

Thu Dec 01, 2022 7:24 am

Hello,
I'm converting XLSX file into PDF file using spire.office-7.11.2 API.
In my attached sample file hockeyplayerdata2018.xlsx, I have two issues stated below.

1. In PlayerData sheet, the Age column values are calculated wrongly.
ie, one year less than the actual value

2. In PlayerData sheet, the date format has been changed in converted PDF file from 01-12-2013 to 2013/12/1.

The screenshots of the issues and sample source code are attached for your reference.
I appreciate your help.

DateFormatAgeIssue.zip
(793.02 KiB) Downloaded 502 times

UshaThavasiappan
 
Posts: 109
Joined: Sat Oct 08, 2022 9:23 am

Thu Dec 01, 2022 11:11 am

Hello,

Thanks for your inquiry.
After preliminary tests, I do notice your issues. To help us work out a solution for you, I have some information to check with you:
1) The region or local of your computer.
2) The date format setting, as shown in the screenshot below.

Sincerely
Abel
E-iceblue support team
Attachments
E40A7882-1857-4e3d-9F6E-FCE08BC77E74.png
E40A7882-1857-4e3d-9F6E-FCE08BC77E74.png (94.68 KiB) Viewed 2729 times
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Thu Dec 01, 2022 11:19 am

Hello,
Yes, please refer the screenshot below for the format.

AgeDOB-RegionClock.png
AgeDOB-RegionClock.png (59.57 KiB) Viewed 2726 times

UshaThavasiappan
 
Posts: 109
Joined: Sat Oct 08, 2022 9:23 am

Fri Dec 02, 2022 10:07 am

Hello,

Thanks for your feedback.
For the issue of the Age column values are calculated wrongly, I have logged it into our bug tracking system with the ticket number SPIREXLS-4326. Our development team will investigate and fix it. Once it is resolved, I will inform you in time. Sorry for the inconvenience caused.

I found that you use the following code to set local to “zh-CN”
Code: Select all
Locale locale = new Locale("zh", "CN");
 Locale.setDefault(locale);

I suggest you use the following code to set local and check if this operation has any effect on this issue(number-amount-values-are-not-converted-properly-t11650.html)
Code: Select all
Locale locale = new Locale("en", "IN");
 Locale.setDefault(locale);


Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Fri Dec 02, 2022 10:45 am

Hello,
Sure, once the bug SPIREXLS-4326 is resolved please let me know in time. It is really affecting my application progress.

Also May I know any workaround for Date format issue.

When I set to the below locale, I still have number format issues. Only for CH, I get perfect output.

Code: Select all
Locale locale = new Locale("en", "IN");
 Locale.setDefault(locale);

UshaThavasiappan
 
Posts: 109
Joined: Sat Oct 08, 2022 9:23 am

Tue Dec 06, 2022 1:57 am

Hello,

Thanks for your feedback.
Sorry for the late reply due to weekend. After preliminary tests, the data format issue and number format issue are related with local setting. I have reported this issue to our development team, they will do further investigation for this issue. And to help us work out a more reasonable solution for your issue, please offer the following message. Thanks for your assistance in advance.
1) The screenshot of the OS loacl (as shown in the screenshot 1 in the attachment)
2) The screenshot of the OS’s number format (as shown in the screenshot 2 in the attachment)
3) The screenshot of the OS’s currency (as shown in the screenshot 3 in the attachment)

Sincerely
Abel
E-iceblue support team
Attachments
Screenshot.zip
(658.17 KiB) Downloaded 474 times
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Tue Dec 06, 2022 5:10 am

Hello,
Sure, herewith I'm attaching screenshots you requested.
Please have a look and provide solution for my issue.

NumberFormatIssueDoc.zip
(137.36 KiB) Downloaded 496 times

UshaThavasiappan
 
Posts: 109
Joined: Sat Oct 08, 2022 9:23 am

Tue Dec 06, 2022 5:50 am

Hello,

Thanks for your more sharing.
Once there are any updates, I'll inform you in time.

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Wed Dec 07, 2022 10:02 am

Hello,

Greeting from E-iceblue.
I have some message to inform you according to our development team:
1) For the date format issue and number format issue, our development team modified the logic of Spire.Xls, now, you doesn’t set local in your code to avoid the number format issue, and at the same time, the date format issue caused by setting local to “zh_CN” has also been resolved.

2) For the issue(SPIREXLS-4326) of the Age column values are calculated wrongly: For the excel file downloaded from website, there will have warning message and the formula in excel file will not be calculated, as shown in the screenshot below. That mean the data of Age column is 1 smaller before calculation than fater calculation. Therefore , if you want the data of Age column to be the calculated value in result PDF file, you need change :
Code: Select all
workbook.getConverterSetting().isReCalculateOnConvert(false);

to:
Code: Select all
workbook.getConverterSetting().isReCalculateOnConvert(true);


I put the complete code below for your reference, and I put the temporary package that includes fixes of theses above issues to our server, you can download it from the following link and have a test.
temporary package: https://www.e-iceblue.com/downloads/Tem ... 7.12.1.zip

Code: Select all
public static void main(String[] args) {
      convertExcelToPdf();
   }
   
    public static void convertExcelToPdf() {
       
        File file = new File("data/hockeyplayerdata2018.xlsx");
        String outputFileName = "output/hockeyplayerdata2018_12_11_8.pdf";
       
        Workbook workbook = new Workbook();
        workbook.loadFromFile(file.getPath());
        workbook.getConverterSetting().setSheetFitToWidth(true);
        workbook.getConverterSetting().isReCalculateOnConvert(true);
       
        for (int i = 0; i < workbook.getWorksheets().size(); i++) {
           
            Worksheet worksheet = workbook.getWorksheets().get(i);
           
            for (int col = worksheet.getFirstColumn(); col <= worksheet.getLastColumn(); col++){
                CellStyle style = worksheet.getColumns()[col-1].getCellStyle();
                style.setShrinkToFit(true);
                style.setWrapText(false);
            }
           PageSetup pageSetup = worksheet.getPageSetup();
            pageSetup.setPrintArea(null);
        }

        workbook.saveToFile(outputFileName, FileFormat.PDF);
       workbook.dispose();
       System.out.println("processed excel file - "+file.getName());
    }


Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Thu Dec 08, 2022 6:21 am

Hello Abel,

I tried to convert my excel files using the temporary version of Spire.Office which you have shared.

1. It is good to know that the date and number format issues are fixed in the API itself. But I found an issue only for 4 digit numbers. For 2,500, it is converted like 250,0. Attached screenshot (TempJar-NumberFormatIssue) for your reference

2. Actually for the issue SPIREXLS-4166 XLSX to PDF conversion throws ClassCastException, your team suggested to use this code "workbook.getConverterSetting().isReCalculateOnConvert(false);". After your suggestion "workbook.getConverterSetting().isReCalculateOnConvert(true);", I tried to convert the file and I got issue in value calculation. Attached screenshot (TempJar-IncorrectValues) for your reference.

I hope the development team can accept these issues to be sorted.

TempJarIssues.zip
(440.26 KiB) Downloaded 490 times

UshaThavasiappan
 
Posts: 109
Joined: Sat Oct 08, 2022 9:23 am

Thu Dec 08, 2022 2:24 pm

Hello,

Thanks for your feedback.
1) For the number issue only for 4 digit numbers, I did notice and logged it into our bug tracking system with the ticket number SPIREXLS-4335. Our development team will investigate and fix it.
2) For issue with number of SPIREXLS-4116 and SPIREXLS-4326, sorry for our oversight.
a. If sheet includes pivot table, you need to set false to “isReCalculateOnConvert” to make sure the result pdf file of pivot table is same as input excel file.
b. For other sheets that doesn’t includes pivot table, you need to set set true to “isReCalculateOnConvert”.
I put the complete code below for your reference.
Code: Select all
public static void main(String[] args) {
   convertExcelToPdf();
}
   
   public static void convertExcelToPdf() {
       
       File file = new File("data/hockeyplayerdata2018.xlsx");
       String outputFileName = "output/hockeyplayerdata2018_12_11_8.pdf";

       Workbook workbook = new Workbook();
       workbook.loadFromFile(file.getPath());
       workbook.getConverterSetting().setSheetFitToWidth(true);
       workbook.getConverterSetting().isReCalculateOnConvert(false);
       
       for (int i = 0; i < workbook.getWorksheets().size(); i++) {
           //If the sheet doesn't include pivot table, calculating the value of sheet
           Worksheet worksheet = workbook.getWorksheets().get(i);
           if (worksheet.getPivotTables().getCount() == 0) {
               worksheet.CalculateAllValue();
           }
           
           for (int col = worksheet.getFirstColumn(); col <= worksheet.getLastColumn(); col++){
               CellStyle style = worksheet.getColumns()[col-1].getCellStyle();
               style.setShrinkToFit(true);
               style.setWrapText(false);
           }
           PageSetup pageSetup = worksheet.getPageSetup();
           pageSetup.setPrintArea(null);
       }

       workbook.saveToFile(outputFileName, FileFormat.PDF);
       workbook.dispose();
       System.out.println("processed excel file - "+file.getName());
   }


Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Mon Dec 12, 2022 4:48 am

Hello,
I tried the code which you shared, I'm getting below issue for two files. Both the files are shared for your reference. Even I tried with the latest spire.office-7.12.2 jar, facing same issue. After including the below code, I'm getting this issue.

java.lang.IllegalArgumentException: Invalid row index.
at com.spire.office.packages.sprvfi.spr⌭┡(Unknown Source)
at com.spire.office.packages.sprzkg.spr┗┓(Unknown Source)
at com.spire.office.packages.sprzkg.spr⅞┒(Unknown Source)
at com.spire.office.packages.sprrok.spr╸╇(Unknown Source)
at com.spire.office.packages.sprrok.spr┅⌬(Unknown Source)
at com.spire.xls.core.spreadsheet.XlsWorkbook.spr┅⌬(Unknown Source)
at com.spire.xls.core.spreadsheet.XlsWorkbook.spr┙⌬(Unknown Source)
at com.spire.xls.Workbook.saveToFile(Unknown Source)


Code: Select all
if (worksheet.getPivotTables().getCount() == 0) {
                       worksheet.CalculateAllValue();
                   }


Also not only for 4 digit numbers, for all number I'm getting format issue. Attached screenshot for your reference.

InvalidRowIndexIssue.zip
(495.77 KiB) Downloaded 483 times

NumberFormatIssues.zip
(377.33 KiB) Downloaded 483 times

UshaThavasiappan
 
Posts: 109
Joined: Sat Oct 08, 2022 9:23 am

Tue Dec 13, 2022 9:40 am

Hello,

Thanks for your feedback.
Please kindly note that the Number format issue (SPIREXLS-4331、SPIREXLS-4335) has been in test phase, and the java jar that I provided last time is a temporary package. Once the official Spire.Office including Number format issue is released, I’ll inform you in time.

In addition, for the invalid row index issue, I used the Spire.Office 7.12.2 to test the files, I found that these files (rieter-review-2017-2021-en.xlsx、Financial-statements-template.xlsx) have’t the issue you mentioned, and I reproduced the issue with the remaining two files. I logged it into our bug tracking system with the ticket number SPIREXLS-4348. Our development team will investigate and fix it. Once it is resolved, I will inform you in time. Sorry for the inconvenience caused.

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Fri Dec 30, 2022 9:51 am

Hello,

Thanks for your patience!
Glad to inform you that we just released Spire.Office for Java 7.12.4 which fixes the issue with SPIREXLS-4348、SPIREXLS-4335、SPIREXLS-4331.
Please download the new version from the following links to test.
Website download link: https://www.e-iceblue.com/Download/office-for-java.html

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Fri Dec 30, 2022 12:34 pm

Hello,
Thanks for the update. I will check my side and I will back if I need any.

UshaThavasiappan
 
Posts: 109
Joined: Sat Oct 08, 2022 9:23 am

Return to Spire.XLS

cron