1
我想在使用Apache POI的Excel单元格中节省时间[hh:mm:ss]。我写的代码如下 -如何从时间对象中删除日期?
FileOutputStream out = new FileOutputStream("dateFormat.xls");
HSSFWorkbook hssfworkbook = new HSSFWorkbook();
HSSFSheet sheet = hssfworkbook.createSheet("new sheet");
HSSFCellStyle cs = hssfworkbook.createCellStyle();
HSSFDataFormat df = hssfworkbook.createDataFormat();
cs.setDataFormat(df.getFormat("h:mm:ss"));
HSSFRow row = sheet.createRow((short)0);
HSSFCell cell = row.createCell((short)0);
//cell.setCellValue(new Time(567898));
cell.setCellValue(new Time(1, 6, 55));
cell.setCellStyle(cs);
hssfworkbook.write(out);
out.close();
现在的问题是,它包括日期和时间。当我在做这个代码生成的excel表单中的单元格的sum
。它给出了incorrect
的结果。
cell.setCellValue(new Time(3, 4, 4)); --->01-01-1970 03:04:04 AM [in excel sheet]
cell2.setCellValue(new Time(1, 6, 51)); --->01-01-1970 01:06:55 AM [in excel sheet]
另一种方式我试着给String
值,在这种情况下,结果是Zero
感谢您的回答,我忘了提及我已经在我的代码中写入'cell.setStyle(cs)'。你可以请建议一些其他的解决方案。 – Priyank 2014-08-28 04:43:21
查看http://stackoverflow.com/a/13466371/1651233 – BobTheBuilder 2014-08-28 04:59:15