I am working in a project where I have data in HH:MM:SS.sss
format, I have to generate report in Excel/Spreadsheet. I am using POI to generate the excel file, but I am facing the following problems:
If I set data in string format i.e
cell.setCellValue("02:45:6.7");
it is impossible to use Excel formulas such asaverage
,sum
, etc. Even if I format the cell in[h]:mm:ss.000;@
i.e.cs.setDataFormat(df.getFormat("[h]:mm:ss.000;@"))
is does not works, as it is string.HSSFCellStyle cs = hssfworkbook.createCellStyle(); HSSFDataFormat df = hssfworkbook.createDataFormat(); cs.setDataFormat(df.getFormat("[h]:mm:ss.000;@"));
Excel does not have any function(as per my knowledge) which takes data in
hh:mm:ss.sss
format, I tried using 'TIME(HH,MM,SS)' and formatting the cell to[h]:mm:ss.000;@
it does not shows value after decimal point replaces it with 000 i.eTIME(02,45,6.7) is displayed as 02:45:6.000
I tried making changes in POI source code, I tried the steps as per in this question https://stackoverflow.com/a/10306350/2513084 Still it does not work. The generated file says - some formulae or name of this file contains built-in functions which Kingsoft Spreadsheet does not support, and recalculation of these formulas or name may cause incorrect results. Microsoft Office was not able to open the file it gave the error File Error: data may have been lost.