Hi,
Hi Kapil,
Style style = book.createStyle();
StyleFlag flag = new StyleFlag();
flag.setNumberFormat(true);
Cell A1 = book.getWorksheets().get(0).getCells().get(“A1”);
A1.setStyle(style);
System.out.println(A1.getDisplayStringValue());
Hi Babar,
Hi Kapil,
Thanks for your further explanation and considering Aspose.Cells.
We were able to understand your problem partially not completely. Could you please provide us a simple excel file which you can create yourself manually using Microsoft Excel and post here for our investigation. You can also add comments inside it.
Are you storing dates in Excel file in the Text format as string and trying to convert those text data into real date objects in your code?
Please also see the code below that converts A1 string value into date format. I have also attached the excel file used in this code for a reference.
Java
Workbook book = new Workbook(“book1.xlsx”);
Cell A1 = book.getWorksheets().get(0).getCells().get(“A1”);
Style style = A1.getStyle();
String format = style.getCustom();
format = format.toUpperCase();
format = format.replace("\", “”);
System.out.println(format);
SimpleDateFormat formatter = new SimpleDateFormat(format);
String dateInString = A1.getStringValue();
System.out.println(dateInString);
Date date = formatter.parse(dateInString);
System.out.println(date);
Console Output:
D-MMM-YYYY
21-Nov-2014
Sun Dec 29 00:00:00 UZT 2013
Hi Shakeel,
format = format.toUpperCase();
format = format.replace("\", “”);
System.out.println(format);
Hi Kapil,
style.setCustom(“dd-mmm-yyyy hh:mm:ss”);
StyleFlag flag = new StyleFlag();
flag.setNumberFormat(true);
Column col = book.getWorksheets().get(0).getCells().getColumns().get(CellsHelper.columnNameToIndex(“K”));
col.applyStyle(style, flag);
Hi Babar,
Hi again,
Worksheet sheet = book.getWorksheets().get(0);
Cells cells = sheet.getCells();
for (int i = 1; i <= cells.getMaxDataRow(); i++)
{
Cell cell = cells.get(i, CellsHelper.columnNameToIndex(“K”));
cell.putValue(cell.getStringValue().trim(), true);
DateTime dTime = (DateTime) cell.getValue();
Date date = dTime.toDate();
System.out.println(date);
}
Hi Team,
Hi Kapil,
Hi Aspose Team,
I have some excel files which are created in US time zone. In these files the date columns have a date-time format of US Time Zone i.e. the format applied on the cell is “MM/dd/yyyy HH:mm AM/PM”. Now this date time format is not available in Indian Time zone. So when I load these excels in java using aspose.cells in India Time zone then for the date-time column the API com.aspose.cells.Cell.getType not giving type as CellValueType.IS_DATE_TIME.
Please check the attached image for your reference. (Verified on version aspose-cells-17.7)
image.png (84.2 KB)
Please share your Excel file so that we could experiment with your file and help you in dealing with this issue. Your sample code will also be helpful. Besides, let us know your expected date.
Could you share two Pdfs (or Excel files). One should have the actual date and other should have expected dates? Thanks for your cooperation in this regard and have a good day.