首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

POI导出excel 范例

2012-09-13 
POI导出excel 实例?/**??*???*/??package??com.justinmobile.payease.admin.commons.excel?import??java.

POI导出excel 实例

?/**?
POI导出excel 范例?*?
POI导出excel 范例??*/?
POI导出excel 范例?package??com.justinmobile.payease.admin.commons.excel;
POI导出excel 范例
POI导出excel 范例?import??java.io.FileNotFoundException;
POI导出excel 范例?import??java.io.FileOutputStream;
POI导出excel 范例?import??java.io.IOException;
POI导出excel 范例?import??java.util.Calendar;
POI导出excel 范例
POI导出excel 范例?import??org.apache.poi.hssf.usermodel.HSSFCell;
POI导出excel 范例?import??org.apache.poi.hssf.usermodel.HSSFCellStyle;
POI导出excel 范例?import??org.apache.poi.hssf.usermodel.HSSFDataFormat;
POI导出excel 范例?import??org.apache.poi.hssf.usermodel.HSSFRow;
POI导出excel 范例?import??org.apache.poi.hssf.usermodel.HSSFSheet;
POI导出excel 范例?import??org.apache.poi.hssf.usermodel.HSSFWorkbook;
POI导出excel 范例
POI导出excel 范例?/**?
POI导出excel 范例?*?生成导出Excel文件对象
POI导出excel 范例?*?
POI导出excel 范例?*??@author??John.Zhu
POI导出excel 范例?*?
POI导出excel 范例??*/?
POI导出excel 范例?public???class??XLSExport??{
POI导出excel 范例
POI导出excel 范例?????//??设置cell编码解决中文高位字节截断?
POI导出excel 范例??????private???static???short??XLS_ENCODING??=??HSSFWorkbook.ENCODING_UTF_16;
POI导出excel 范例
POI导出excel 范例?????//??定制日期格式?
POI导出excel 范例??????private???static??String?DATE_FORMAT??=???"?m/d/yy?"?;??//??"m/d/yy?h:mm"
POI导出excel 范例
POI导出excel 范例?????//??定制浮点数格式?
POI导出excel 范例??????private???static??String?NUMBER_FORMAT??=???"?#,##0.00?"?;
POI导出excel 范例
POI导出excel 范例?????private??String?xlsFileName;
POI导出excel 范例
POI导出excel 范例?????private??HSSFWorkbook?workbook;
POI导出excel 范例
POI导出excel 范例?????private??HSSFSheet?sheet;
POI导出excel 范例
POI导出excel 范例?????private??HSSFRow?row;
POI导出excel 范例
POI导出excel 范例?????/**?
POI导出excel 范例?????*?初始化Excel
POI导出excel 范例?????*?
POI导出excel 范例?????*??@param??fileName
POI导出excel 范例?????*????????????导出文件名
POI导出excel 范例??????*/?
POI导出excel 范例??????public??XLSExport(String?fileName)??{
POI导出excel 范例?????????this?.xlsFileName??=??fileName;
POI导出excel 范例?????????this?.workbook??=???new??HSSFWorkbook();
POI导出excel 范例?????????this?.sheet??=??workbook.createSheet();
POI导出excel 范例????}?
POI导出excel 范例?
POI导出excel 范例??????/**?
POI导出excel 范例?????*?导出Excel文件
POI导出excel 范例?????*?
POI导出excel 范例?????*??@throws??XLSException
POI导出excel 范例??????*/?
POI导出excel 范例??????public???void??exportXLS()??throws??XLSException??{
POI导出excel 范例?????????try???{
POI导出excel 范例????????????FileOutputStream?fOut??=???new??FileOutputStream(xlsFileName);
POI导出excel 范例????????????workbook.write(fOut);
POI导出excel 范例????????????fOut.flush();
POI导出excel 范例????????????fOut.close();
POI导出excel 范例????????}???catch??(FileNotFoundException?e)??{
POI导出excel 范例?????????????throw???new??XLSException(?"?生成导出Excel文件出错!?"?,?e);
POI导出excel 范例????????}???catch??(IOException?e)??{
POI导出excel 范例?????????????throw???new??XLSException(?"?写入Excel文件出错!?"?,?e);
POI导出excel 范例????????}?
POI导出excel 范例?
POI导出excel 范例????}?
POI导出excel 范例?
POI导出excel 范例??????/**?
POI导出excel 范例?????*?增加一行
POI导出excel 范例?????*?
POI导出excel 范例?????*??@param??index
POI导出excel 范例?????*????????????行号
POI导出excel 范例??????*/?
POI导出excel 范例??????public???void??createRow(?int??index)??{
POI导出excel 范例?????????this?.row??=???this?.sheet.createRow(index);
POI导出excel 范例????}?
POI导出excel 范例?
POI导出excel 范例??????/**?
POI导出excel 范例?????*?设置单元格
POI导出excel 范例?????*?
POI导出excel 范例?????*??@param??index
POI导出excel 范例?????*????????????列号
POI导出excel 范例?????*??@param??value
POI导出excel 范例?????*????????????单元格填充值
POI导出excel 范例??????*/?
POI导出excel 范例??????public???void??setCell(?int??index,?String?value)??{
POI导出excel 范例????????HSSFCell?cell??=???this?.row.createCell((?short?)?index);
POI导出excel 范例????????cell.setCellType(HSSFCell.CELL_TYPE_STRING);
POI导出excel 范例????????cell.setEncoding(XLS_ENCODING);
POI导出excel 范例????????cell.setCellValue(value);
POI导出excel 范例????}?
POI导出excel 范例?
POI导出excel 范例??????/**?
POI导出excel 范例?????*?设置单元格
POI导出excel 范例?????*?
POI导出excel 范例?????*??@param??index
POI导出excel 范例?????*????????????列号
POI导出excel 范例?????*??@param??value
POI导出excel 范例?????*????????????单元格填充值
POI导出excel 范例??????*/?
POI导出excel 范例??????public???void??setCell(?int??index,?Calendar?value)??{
POI导出excel 范例????????HSSFCell?cell??=???this?.row.createCell((?short?)?index);
POI导出excel 范例????????cell.setEncoding(XLS_ENCODING);
POI导出excel 范例????????cell.setCellValue(value.getTime());
POI导出excel 范例????????HSSFCellStyle?cellStyle??=??workbook.createCellStyle();??//??建立新的cell样式?
POI导出excel 范例?????????cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat(DATE_FORMAT));??//??设置cell样式为定制的日期格式?
POI导出excel 范例?????????cell.setCellStyle(cellStyle);??//??设置该cell日期的显示格式?
POI导出excel 范例?????}?
POI导出excel 范例?
POI导出excel 范例??????/**?
POI导出excel 范例?????*?设置单元格
POI导出excel 范例?????*?
POI导出excel 范例?????*??@param??index
POI导出excel 范例?????*????????????列号
POI导出excel 范例?????*??@param??value
POI导出excel 范例?????*????????????单元格填充值
POI导出excel 范例??????*/?
POI导出excel 范例??????public???void??setCell(?int??index,??int??value)??{
POI导出excel 范例????????HSSFCell?cell??=???this?.row.createCell((?short?)?index);
POI导出excel 范例????????cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
POI导出excel 范例????????cell.setCellValue(value);
POI导出excel 范例????}?
POI导出excel 范例?
POI导出excel 范例??????/**?
POI导出excel 范例?????*?设置单元格
POI导出excel 范例?????*?
POI导出excel 范例?????*??@param??index
POI导出excel 范例?????*????????????列号
POI导出excel 范例?????*??@param??value
POI导出excel 范例?????*????????????单元格填充值
POI导出excel 范例??????*/?
POI导出excel 范例??????public???void??setCell(?int??index,??double??value)??{
POI导出excel 范例????????HSSFCell?cell??=???this?.row.createCell((?short?)?index);
POI导出excel 范例????????cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
POI导出excel 范例????????cell.setCellValue(value);
POI导出excel 范例????????HSSFCellStyle?cellStyle??=??workbook.createCellStyle();??//??建立新的cell样式?
POI导出excel 范例?????????HSSFDataFormat?format??=??workbook.createDataFormat();
POI导出excel 范例????????cellStyle.setDataFormat(format.getFormat(NUMBER_FORMAT));??//??设置cell样式为定制的浮点数格式?
POI导出excel 范例?????????cell.setCellStyle(cellStyle);??//??设置该cell浮点数的显示格式?
POI导出excel 范例?????}?
POI导出excel 范例?
POI导出excel 范例}
调用的过程:
POI导出excel 范例?/**?
POI导出excel 范例?*?
POI导出excel 范例??*/?
POI导出excel 范例?package??com.justinmobile.payease.admin.commons.excel;
POI导出excel 范例
POI导出excel 范例?import??java.util.Calendar;
POI导出excel 范例
POI导出excel 范例?/**?
POI导出excel 范例?*?导出Excel示例
POI导出excel 范例?*?
POI导出excel 范例?*??@author??John.Zhu
POI导出excel 范例?*?
POI导出excel 范例??*/?
POI导出excel 范例?public???class??XLSDemo??{
POI导出excel 范例
POI导出excel 范例?????public???static???void??main(String[]?args)??{
POI导出excel 范例????????System.out.println(?"?开始导出Excel文件?"?);
POI导出excel 范例????????XLSExport?e??=???new??XLSExport(?"?d:/test.xls?"?);
POI导出excel 范例????????e.createRow(?0?);
POI导出excel 范例????????e.setCell(?0?,??"?编号?"?);
POI导出excel 范例????????e.setCell(?1?,??"?名称?"?);
POI导出excel 范例????????e.setCell(?2?,??"?日期?"?);
POI导出excel 范例????????e.setCell(?3?,??"?金额?"?);
POI导出excel 范例????????e.createRow(?1?);
POI导出excel 范例????????e.setCell(?0?,??1?);
POI导出excel 范例????????e.setCell(?1?,??"?工商银行?"?);
POI导出excel 范例????????e.setCell(?2?,?Calendar.getInstance());
POI导出excel 范例????????e.setCell(?3?,??111123.99?);
POI导出excel 范例????????e.createRow(?2?);
POI导出excel 范例????????e.setCell(?0?,??2?);
POI导出excel 范例????????e.setCell(?1?,??"?招商银行?"?);
POI导出excel 范例????????e.setCell(?2?,?Calendar.getInstance());
POI导出excel 范例????????e.setCell(?3?,??222456.88?);
POI导出excel 范例?????????try???{
POI导出excel 范例????????????e.exportXLS();
POI导出excel 范例????????????System.out.println(?"?导出Excel文件[成功]?"?);
POI导出excel 范例????????}???catch??(XLSException?e1)??{
POI导出excel 范例????????????System.out.println(?"?导出Excel文件[失败]?"?);
POI导出excel 范例????????????e1.printStackTrace();
POI导出excel 范例????????}?
POI导出excel 范例????}?
POI导出excel 范例}转自:http://www.blogjava.net/zJun/archive/2007/01/22/95385.html

热点排行