POI HSSF 单元格和字体设置

添加区域,合并单元格 Region region = new Region((short)rowFrom,(short)columnFrom,(short)rowTo,(short)columnTo); sheet.addMergedRegion(region); //得到所有区域 sheet.getNumMergedRegions() render_code(); 5、设置列宽、行高 sheet.setColumnWidth((short)column,(short)width); row.setHeight((short)height); 常用单元格边框格式 虚线HSSFCellStyle.BORDER_DOTTED 实线HSSFCellStyle.BORDER_THIN 代码public static HSSFCellStyle getCellStyle(short type) { HSSFWorkbook wb = new HSSFWorkbook(); HSSFCellStyle style = wb.createCellStyle(); style.setBorderBottom(type);//下边框 style.setBorderLeft(type);//左边框 style.setBorderRight(type);//右边框 style.setBorderTop(type);//上边框 return style; } render_code(); 设置字体和内容位置 代码HSSFFont f = wb.createFont(); f.setFontHeightInPoints((short) 11);//字号 f.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);//加粗 style.setFont(f); style.setAlignment(HSSFCellStyle.ALIGN_CENTER);//左右居中 style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);//上下居中 style.setRotation(short rotation);//单元格内容的旋转的角度 HSSFDataFormat df = wb.createDataFormat(); style1.setDataFormat(df.getFormat("0.00%"));//设置单元格数据格式 cell.setCellFormula(string);//给单元格设公式 style.setRotation(short rotation);//单元格内容的旋转的角度 cell.setCellStyle(style);

你可能感兴趣的:(java)