Encoding issue while reading excel/csv file

Hi Santhosh,


Thank you for sharing the sample CSV files.

We have evaluated the presented scenario while using the latest version of Aspose.Cells for Java 8.6.0 and the following piece of code. Please note, we are not able to see any issue (as mentioned in this thread) while loading the CSV (test2.csv as it contains the problematic characters) or saving it back. Please check the attached snapshot of the Excel view where we saved the resultant file in XLSX file format. You may clearly see that all problematic characters are displayed fine.

That said, we have also tested the case by displaying the problematic values/charchters on the Eclipse output terminal, in that case we have observed that the said charchters are bieng displayed as question marks (?). Please note, this is due to the encoding standard set for the console terminal and can easily be override using the following steps.

  • Click on Run menu and select Run Configuration.
  • While selecting your project from the left hand pane, click on the Common tab.
  • Under the Encoding heading, default encoding should have been selected by default. Please change it to appropriate encoding standard (ISO-8859-1 in this case), and run the process again.

Java

TxtLoadOptions options = new TxtLoadOptions(LoadFormat.CSV);
options.setSeparator(’;’);
options.setEncoding(Encoding.getEncoding(“ISO-8859-1”));
options.setMemorySetting(MemorySetting.MEMORY_PREFERENCE);
Workbook workbook = new Workbook(“D:/test2.csv”, options);
Worksheet worksheet = workbook.getWorksheets().get(0);
for(int i=0; i<11; i++)
{
System.out.println(worksheet.getCells().get(i, CellsHelper.columnNameToIndex(“J”)).getDisplayStringValue());
System.out.println(worksheet.getCells().get(i, CellsHelper.columnNameToIndex(“W”)).getDisplayStringValue());
}
workbook.save(“D:/output.xlsx”, SaveFormat.XLSX);

Output after changing the Encoding for Console

indexé révisable

Amortissement progressif avéêëc
indexé révisable
Amortissement linéaire
indexé révisable
Amortissement progressif avéêëc
indexé révisable
Amortissement progressif avéêëc
indexé révisable
Amortissement progressif avéêëc
indexé révisable
Amortissement linéaire
indexé révisable
Amortissement progressif avéêëc
indexé révisable
Amortissement progressif avéêëc
indexé révisable
Amortissement progressif avéêëc
indexé révisable
Amortissement progressif avéêëc

Hi Babar Raza,

Thanks a lot for the reply,

Did you test this in Linux server?

We have issue only in Linux server(only for CSV), in windows it is working fine.

We are using the Apose 8.5.2 version and I confirm that when I print the value in tomcat log

I am getting the value "Amortissement progressif av???c"

Please let us know if we need to upgrade to 8.5.6.

-Regards,

Santhosh.

Hi Santhosh,

I have tested it on the Linux (CentOS) as well. Please check the attached snapshot for the output in Linux (Netbeans). Please try the case with latest version of Aspose.Cells for Java (Latest Version). In case you get the correct results with latest revision then it is possible that your current version has some bug regarding the encoding. In that case you have to upgrade. However, if you do not get the desired results with latest revision too then you need to involve your system administators in this disussion as we have tested that the problem is not related to the Aspose.Cells APIs anymore, it could be related to the system/tomcat configurations.

Hi Babar Raza,

Thanks a lot for the reply.

Sorry for the trouble I gave you :)

The issue was with Linux server.

I have fixed the issue by adding below properties.

-Dfile.encoding=Cp1252

-Djavax.servlet.request.encoding=Cp1252

No code changes required..

-Regards,

Santhosh.

Hi Santhosh,


Thank you for sharing the solution, and it is good to know that you are up & running again. Please feel free to contact us back in case you need our further assistance with Aspose APIs.