日期:2014-05-17 浏览次数:21158 次
public static boolean CreateExcel()
{
String FileName;
FileName = "";
FileOutputStream fileOut = null;
try
{
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet();
wb.setSheetName(0,"测试",HSSFWorkbook.ENCODING_UTF_16);
HSSFRow row0 = sheet.createRow(0);
HSSFRow row1 = sheet.createRow(1);
String strf = "1.01";
float f = Float.valueOf(strf).floatValue();
HSSFCell cell = row0.createCell((short)0);
cell.setCellValue( strf); //这个是字符的1.01,导出后每次都得手工改成数字型
cell = row1.createCell((short)0);
cell.setCellValue( f); //单元格里看到的是1.01,但实际值却是1.00999999046325 ,数据多时,恐有误差。
String filepath = "c:\\poi.xls";
fileOut = new FileOutputStream(filepath);
wb.write(fileOut);
fileOut.flush();
fileOut.close();
}
catch(Exception ex)
{
ex.printStackTrace();
return false;
}
finally
{
try
{
fileOut.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
return true;
}