有必要在字段中设置格式。我在下面的jsp页面中做了这个例子,但是,它有效。没有必要将值转换为浮点数。将“.0”放在最后,CellStyle 属性会很小心。
<%@ page import="java.io.FileOutputStream"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFSheet"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFWorkbook"%>
<%@ page import="org.apache.poi.ss.usermodel.Cell"%>
<%@ page import="org.apache.poi.ss.usermodel.CellStyle"%>
<%@ page import="org.apache.poi.ss.usermodel.DataFormat"%>
<%@ page import="org.apache.poi.ss.usermodel.Row"%>
<%
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("format sheet");
CellStyle style;
DataFormat format = wb.createDataFormat();
short rowNum = 0;
short colNum = 0;
Row row = sheet.createRow(rowNum++);
Cell cell = row.createCell(colNum);
cell.setCellValue(361272004652.0);
style = wb.createCellStyle();
style.setDataFormat(format.getFormat("0"));
cell.setCellStyle(style);
FileOutputStream fileOut = new FileOutputStream("filexample.xls");
wb.write(fileOut);
fileOut.close();
%>