How do I create a cell with Time format?
Excel has to show “Time” format.
I use cells-java 21.7.
See the sample code for your reference.
e.g.
Sample code:
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.getWorksheets().get(0);
worksheet.getCells().get("A1").putValue("11:12:20", true);
Style style = worksheet.getCells().get("A1").getStyle();
style.setCustom("h:mm AM/PM");
worksheet.getCells().get("A1").setStyle(style);
worksheet.getCells().get("A2").putValue(DateTime.getNow());
Style style1 = worksheet.getCells().get("A2").getStyle();
style1.setNumber(21);
worksheet.getCells().get("A2").setStyle(style1);
workbook.save("f:\\files\\out1.xlsx");
Also, see the document for your further reference:
Excel shows format for both cells as “Custom”, not “Time”.
We reproduced the issue as you mentioned. When opening the output file into MS Excel manually, it shows it as “Custom” instead of “Time”. We need to investigate your issue in details.
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): CELLSJAVA-45268
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.