xssfcell 宽高
时间: 2023-10-12 10:11:36 浏览: 106
XSSFCell 的宽度和高度可以通过设置单元格的样式来调整。你可以使用 XSSFCellStyle 类的 setWidth 和 setHeightInPoints 方法来设置单元格的宽度和高度。
例如,以下代码可以将单元格 A1 的宽度设置为 20 个字符的宽度,高度设置为 30 个点:
```
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("Sheet1");
XSSFRow row = sheet.createRow(0);
XSSFCell cell = row.createCell(0);
cell.setCellValue("Hello, World!");
XSSFCellStyle style = workbook.createCellStyle();
style.setWrapText(true);
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
style.setBorderBottom(BorderStyle.THIN);
style.setBorderTop(BorderStyle.THIN);
style.setBorderLeft(BorderStyle.THIN);
style.setBorderRight(BorderStyle.THIN);
style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
style.setTopBorderColor(IndexedColors.BLACK.getIndex());
style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
style.setRightBorderColor(IndexedColors.BLACK.getIndex());
style.setFont(workbook.createFont());
style.setWidth(20 * 256); // 20 characters wide
style.setHeightInPoints(30); // 30 points tall
cell.setCellStyle(style);
```
注意,setWidth 方法使用的是 1/256 个字符的宽度单位,而 setHeightInPoints 方法使用的是点(point)为单位。
阅读全文
相关推荐



















