poi3.17使用
package lucene;import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import java.io.FileOutputStream;/*** lucene全文檢索測試類* Created by Administrator on 2018/7/10.*/
public class LuceneTestController {//poi導出excelpublic void exportExcel() throws Exception{HSSFWorkbook wb = new HSSFWorkbook();HSSFSheet sheet = wb.createSheet("sheet name");//合并單元格sheet.addMergedRegion(new CellRangeAddress(0, 2, 0, 5));//設置第一列單元格寬度sheet.setColumnWidth(0,100*100);//設置第二列單元格寬度sheet.setColumnWidth(1,100*100);//創建第一行HSSFRow row0 = sheet.createRow(0);//創建第二行HSSFRow row1 = sheet.createRow(1);//設置第一行單元格高度row0.setHeight((short) 400);//創建第一行第一列單元格HSSFCell cell0_1 = row0.createCell(0);//創建第二行第一列單元格HSSFCell cell0_2 = row1.createCell(0);//設置單元格的值cell0_1.setCellValue("項目施工進度管理系統");//改變字體樣式,步驟HSSFFont hssfFont = wb.createFont();//設置字體,紅色hssfFont.setColor(HSSFFont.COLOR_RED);//字體粗體顯示hssfFont.setBold(true);hssfFont.setFontName("宋體");// 字體大小hssfFont.setFontHeightInPoints((short) 22);//設置樣式HSSFCellStyle cellStyle = wb.createCellStyle();cellStyle.setFont(hssfFont);//設置單元格背景色cellStyle.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.getIndex());cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);//設置居中cellStyle.setAlignment(HorizontalAlignment.CENTER);//水平居中cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);//垂直居中//設置邊框cellStyle.setBorderBottom(BorderStyle.THIN); //下邊框cellStyle.setBorderLeft(BorderStyle.DASH_DOT_DOT);//左邊框cellStyle.setBorderTop(BorderStyle.THIN);//上邊框cellStyle.setBorderRight(BorderStyle.THIN);//右邊框//3.單元格使用樣式,設置第一行第一列單元格樣式cell0_1.setCellStyle(cellStyle);cell0_2.setCellStyle(cellStyle);//生成excel文件FileOutputStream fileOut = new FileOutputStream("e:\\"+System.currentTimeMillis()+".xls");wb.write(fileOut);fileOut.close();/* struts導出excel,前端需要是提交form形式,否則,點擊導出不會彈出框HSSFWorkbook wb = exportExcel(projectId, blockId, buildingId,buildingCode);// 生成excel文件String fileName = String.valueOf(Calendar.getInstance().getTimeInMillis()).concat(".xls");// 清空responsethis.getResponse().reset();this.getResponse().addHeader("Content-Disposition","attachment;filename=" + new String(fileName.getBytes()));this.getResponse().setContentType("application/vnd.ms-excel;charset=utf-8");OutputStream os = this.getResponse().getOutputStream();wb.write(os);if (os != null) {os.close();os = null;}wb.close();*/}
}
轉自:https://blog.csdn.net/lhp_36kr/article/details/80139869
總結
- 上一篇: 关于wemall,你知道多少?
- 下一篇: 工程材料(2)铁碳相图