欢迎来到天天文库
浏览记录
ID:34723839
大小:48.48 KB
页数:5页
时间:2019-03-10
《java用poi创建2007excel带样式和给07excel追加数据》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、packagecom.javafly.sms.schedule;importjava.io.File;importjava.io.FileInputStream;importjava.io.FileNotFoundException;importjava.io.FileOutputStream;importjava.io.IOException;importjava.io.OutputStream;importorg.apache.poi.hssf.usermodel.HSSFCellStyle;importorg.apache.poi.hssf.util.HSSFCol
2、or;importorg.apache.poi.ss.usermodel.Cell;importorg.apache.poi.xssf.usermodel.XSSFCellStyle;importorg.apache.poi.xssf.usermodel.XSSFFont;importorg.apache.poi.xssf.usermodel.XSSFRow;importorg.apache.poi.xssf.usermodel.XSSFSheet;importorg.apache.poi.xssf.usermodel.XSSFWorkbook;/***创建07Excel
3、样式自动换行等*给07EXCEL追加数据**@authorAdministrator**/publicclassExcelOperate{/***给Excel追加数据测试*/publicvoidaddData(StringfilePath,StringfileName){//输出流try{FileInputStreamis=newFileInputStream(filePath+fileName);XSSFWorkbookwb=newXSSFWorkbook(is);XSSFSheetsheet1=wb.getSheet("web日报");System.out.print
4、ln(sheet1.getLastRowNum());XSSFRowrow=sheet1.createRow(sheet1.getLastRowNum()+1);row.setHeightInPoints((short)25);//给这一行赋值row.createCell(0).setCellValue("20120710");row.createCell(1).setCellValue("23");row.createCell(2).setCellValue("43");row.createCell(3).setCellValue("2.213213");row.cre
5、ateCell(4).setCellValue("234");row.createCell(5).setCellValue("22");row.createCell(6).setCellValue("");row.createCell(7).setCellValue("");row.createCell(8).setCellValue("");XSSFCellStylecellStyle=wb.createCellStyle();XSSFFontfont=wb.createFont();font.setFontHeightInPoints((short)11);font.
6、setFontName("黑体");cellStyle.setFont(font);cellStyle.setAlignment(HSSFCellStyle.ALIGN_JUSTIFY);cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);//下边框cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框cellStyle.setBorder
7、Top(HSSFCellStyle.BORDER_THIN);//上边框cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框setCellStyle(cellStyle,sheet1,row);FileOutputStreamos=newFileOutputStream(filePath+fileName);wb.write(os);is.close();os.close();}catch(Exceptione){e.printStackTrace();}}/***
此文档下载收益归作者所有