We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Month name not in English for cellObj.getStringValue() styled with custom Style "dd MMM yyyy HH:mm:ss"

Hi,


We use Aspose to read Excel files. If we encounter a Cell of type 1 (date), we set custom style “dd MMM yyyy HH:mm:ss” for the cell as:

styleObj.setCustom(“dd MMM yyyy HH:mm:ss”);
cellObj.setStyle(styleObj);

When reading the value using cellObj.getStringValue() we get month name in languages like Dutch, Portugese,… ( I guess, depending on the some locale setting on the System in which the excel file is created).

I want the return string of getStringValue() to return values only in English irrespective of where the Excel file is created. Can this be done.

Note: I would be better if this can be achieved using some Cell level function rather than changing some language/locale level settings on Workbook/Worksheet level.

Hi,


Thanks for your posting and using Aspose.Cells.

If you change the style of the cell, then get its string value, date will be changed accordingly.

Please see the following sample code, read its comments, check its sample Excel file and Console Output for your reference.

You will find that the date in cell A1 is in Dutch format while the dates in column E are normal dates but the code reads them as Dutch dates and prints them on console.

Java
//Load sample workbook
Workbook wb = new Workbook(dirPath + “sample.xlsx”);

//Access first worksheet
Worksheet ws = wb.getWorksheets().get(0);

//Access the cell A1, it contains Dutch(Belgium) style
Cell a1 = ws.getCells().get(“A1”);

//Access the Dutch style
Style dutchStyle = a1.getStyle();

//Read all the dates in column E but in Dutch style
for(int i=0; i<30; i++)
{
//Access column E cell
Cell colE = ws.getCells().get(i, 4);

//Save its style
Style originalStyle = colE.getStyle();

//Set the Dutch style
colE.setStyle(dutchStyle);

//Print the Dutch Style Date on console
System.out.println(colE.getStringValue());

//Reset the column E cell style
colE.setStyle(originalStyle);
}

Console Output
dinsdag 4 april 2017
woensdag 5 april 2017
donderdag 6 april 2017
vrijdag 7 april 2017
zaterdag 8 april 2017
zondag 9 april 2017
maandag 10 april 2017
dinsdag 11 april 2017
woensdag 12 april 2017
donderdag 13 april 2017
vrijdag 14 april 2017
zaterdag 15 april 2017
zondag 16 april 2017
maandag 17 april 2017
dinsdag 18 april 2017
woensdag 19 april 2017
donderdag 20 april 2017
vrijdag 21 april 2017
zaterdag 22 april 2017
zondag 23 april 2017
maandag 24 april 2017
dinsdag 25 april 2017
woensdag 26 april 2017
donderdag 27 april 2017
vrijdag 28 april 2017
zaterdag 29 april 2017
zondag 30 april 2017
maandag 1 mei 2017
dinsdag 2 mei 2017
woensdag 3 mei 2017