Excel date format is not coming properly in word document

Hi ,

This is Madhu and my query is that,

I have a excel sheet where a particular cell has data in date format.

eg:- my excel cell data is

June 11, 2008
( if it in date format ) and 39610 (If it is in general format).

(I came to know this by open excel and right click and format cells)

My java code is getting 39610. But I want data format as it is.

My java code to get the particular column after open the excel sheet is

String exceldata=worksheet.getCells().getCell(4, 5).getStringValue();

The result string is showing 39610.

I need date format .

Please help me out to solve the issue.

Thanks,

Madhu

Hi,

Well, you may try to set custom date format before retrieving the value from the cells.

i.e..,

Style style = cell.getStyle();
style.setCustom("mm/dd/yyyy");
cell.setStyle(style);
String strVal = cell.getStringValue();

Thank you.

Hi Amjad,

Thanks for your reply.

But, the code is not doing for me.

Still it is giving me the same number format.

Can you help me by specifying another way.

Thanks,

Madhu

Hi,

Well, I don't get the problem you have mentioned, I can retrieve dates fine using Cell.getStringValue() method. Which version of Aspose.Cells for Java you are using, I am using the latest version / fix 1.9.5.9.

Could you post your template file with sample code here, we will check it soon.

Thank you.

Hi Madhu,

If the cell format in your template excel file is Date format, Aspose will return the value in date format too when you call cell.getStringValue() even without resetting custom style for this cell. So, it is strange for you case, please post your template file here, we will check it soon. And I think you can try our 1.9.5.x versions first to check whether it can work fine, thank you.

Hi Amjad and join,

We are using Apsose LicenseVersion-2.0 and Product is- Aspose.Total for Java

and I do not know more details how to know version and all. Beacause already it's in library folder.

here i am providig my code to read the data and I attached the Excel file.

Style style = worksheet.getCells().getCell(7, 2).getStyle();
style.setCustom("mm/dd/yyyy");
worksheet.getCells().getCell(7, 2).setStyle(style);
getdata = worksheet.getCells().getCell(7,2).getStringValue();

One more thing, if I want to copy the same data from one sheet to another sheet it is giving me the same result( Paste as a link)

Thanks

Madhu


Hi Madhu,

Thanks for providing us the template file.

To get the version of the product, you may try the following code:

//Instantiating a Workbook object
Workbook workbook = new Workbook();
System.out.println(CellsHelper.getReleaseVersion());

And I have tested the following code with your template file , it works fine. It gives me "06/10/2009".

Sample code:

Workbook workbook = new Workbook();
workbook.open("e:\\files\\Test_for_date.xls");
Worksheet worksheet = workbook.getWorksheets().getSheet(0);
Cells cells = worksheet.getCells();
Cell cell = cells.getCell(7,1);

Style style = worksheet.getCells().getCell(7, 1).getStyle();
style.setCustom("mm/dd/yyyy");
cell.setStyle(style);
System.out.println(cell.getStringValue());

I have also attached the latest fix of Aspose.Cells for Java for you, could you try it and give us your feedback.

Thank you.

Hi Amjad,

my aspose.cells.jar is not supporting the method given by you.

(CellsHelper.getReleaseVersion())

What I did is I removed the existed Aspose.Cells.jar and placed your new jar over there and the method is supporting. But, the application server is getting close whe it reaches the statement

Workbook workbook = new Workbook();

(I think License is not upgraded)

Why it is happening like this and What I have to do for the temporary access to check whether it is working or not?

Thanks

Madhu

Hi Madhu,

Well, to check the issue temporarily if it works with the new fix (provided by me in my previous post), you may comment out the licensing code (the two lines only in your code).

For your info, if your license file is expired to use the new fix, you need to upgrade your subsription.

Thank you.

Hi Amjad,

I tried in that way. But, what is happening is that whenever I am creating new instrance for Wordbook, the server is getting closed.

Here is the code

Workbook workbook = new Workbook();

(I check it out through break points.)

When the cursor comes to this line the server is closing .

Here I am attaching the error message

Thanks

Madhu

Hi,

Thanks for providing us error info,

It looks strange. We will check your issue and get back to you soon.

By the way could you try our latest official release 1.9.5: http://www.aspose.com/community/files/51/file-format-components/aspose.cells/entry132221.aspx And please replace the older Aspose.Cell.jar file with new one with dom4j-1.6.1 file.

Thank you.

Hi Madhu,

Which one version are you using? There are two versions in our official release, one is for JDK/JRE 1.5, and the other is for JDK/JRE1.4.2 later, because your web server's JDK/JRE is 1.4, so please download our official release 1.9.5 as Amjad guided, and use the corresponding jar for JDK1.4 to try again, thank you.

Hi Amjad and join,

Thanks for your information. I will get back to you with the result.

Thanks

Madhu

Hi Amjad,

Thanks a lot....

It is working fine.

Thanks

madhu