//定义一个新的工作簿 XSSFWorkbook wb = new XSSFWorkbook(); //创建一个Sheet页 XSSFSheet sheet = wb.createSheet(title); //设置行高 sheet.setDefaultRowHeight((short) (2 * 256)); //为有数据的每列设置列宽 for (int i = 0; i < headList.size(); i++) { sheet.setColumnWidth(i, 8000); } //设置单元格字体样式 XSSFFont font = wb.createFont(); font.setFontName("等线"); font.setFontHeightInPoints((short) 16);
业务需求,自己研究学习并且记录一下笔记:
创建行
XSSFRow row = sheet.createRow(x);//创建一行,从0开始算起
//合并单元格CellRangeAddress构造参数依次表示起始行,截至行,起始列, 截至列,从0开始算单元格 CellRangeAddress rangeAddress = new CellRangeAddress(0, 0, 0, 0); sheet.addMergedRegion(rangeAddress);
设置单元格样式:
// 创建单元格文字居中样式并设置标题单元格居中 XSSFCellStyle cellStyle = wb.createCellStyle(); cellStyle.setAlignment(HorizontalAlignment.CENTER);//水平居中 cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);//垂直居中 titleCell.setCellStyle(cellStyle);
还未完成,后续补充............
标签:居中,cellStyle,java,wb,表格,样式,单元格,Excel,sheet From: https://www.cnblogs.com/ssbxfsrm/p/17137876.html