Hi,
Hi,
Thanks for your posting and using the Aspose.Cells for Java.
Please download and use the latest version:
Aspose.Cells for Java (Latest Version)
Below is a code example that illustrates how to get your desired time format. The code basically enters the current date into cell A1 and then format it as a Time.
I have also attached the output xlsx file and the screenshot for a reference.
Java
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.getWorksheets().get(0);
Cell a1 = worksheet.getCells().get(“A1”);
//Enter current date and time
a1.putValue(DateTime.getNow());
//Format it as time
Style st = a1.getStyle();
st.setCultureCustom(“[$-409]h:mm\ AM/PM;@”);
st.setCustom(“[$-409]h:mm\ AM/PM;@”);
a1.setStyle(st);
workbook.save(“F:\Shak-Data-RW\Downloads\output.xlsx”);
Screenshot:
Thanks for answer but this is not what I want.
Hi,
Will you please elaborate more?
Please provide me your source xls/xlsx file and the expected output. You can create source file manually using Ms-Excel 2010.
Hi,
Please use the following code to find if the cell’s value is date time.
Java
if (cell.getType() == CellValueType.IS_DATE_TIME)
{
//access your value
}
Hi,
Hi,
Please use Cell.getStringValue() property. It will return you correct time.
Please see the following code and its output.
Java
String filePath = “F:\Shak-Data-RW\Downloads\time.xls”;
Workbook workbook = new Workbook(filePath);
Worksheet worksheet = workbook.getWorksheets().get(0);
Cell cell = worksheet.getCells().get(“A1”);
System.out.println(cell.getStringValue());
workbook.save(“F:\Shak-Data-RW\Downloads\output.xlsx”);
Output:
22:30