欢迎来到天天文库
浏览记录
ID:51693539
大小:91.50 KB
页数:14页
时间:2020-03-15
《POI操作excel示例工具类.doc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、由于近期项目要用到excel来转存页面中的表单数据,对poi操作excel进行了一番了解,写了以下,但总觉的不是很好特此:发布在此供大家评论,广义集思,还望多多指教 1.workBook处理类Java代码/** * Excel WorkBook工具类 * @author dsy * @version 1.0 */ public class ExcelWorkBook { public HSSFWorkbook workbook = null; public static HSSFWorkbook workbookTemp = null;
2、 //设置当前workbookName private String workbookName = null; private HSSFSheet sheet = null; private FileOutputStream fileOut; public ExcelWorkBook() { if(workbook != null) { workbook = null; } workbook = workbookTemp; }
3、 public ExcelWorkBook(String workbookName) { workbook = workbookTemp; setWorkbookName(workbookName); } public String getWorkbookName() { return workbookName; } public void setWorkbookName(String workbookName) { workbookName = workbookN
4、ame; } public HSSFSheet getSheet() { sheet = workbook.createSheet(getWorkbookName()); return sheet; } /** * 用于stylUtils的所需要的workbook必须项所做的处理 * @return */ public static HSSFWorkbook getWorkbook() { return workbookTemp;
5、 } public static void setWorkbook(HSSFWorkbook workbook) { workbookTemp = workbook; } /** * 输入当前WorkBook为下载临时文件记录 * @param excelName */ public void writerFileStream(String excelName) { try { fileOut = new FileOutputStream
6、(excelName); workbook.write(fileOut); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace();
7、 } finally { try { fileOut.flush(); fileOut.close(); if(workbook != null) { workbook = null; } } catch
此文档下载收益归作者所有