按照您的思路,我对每个单元格计算了高度,没生效,代码是哪里有问题吗?
// 一行行,一个个单元格计算高度,取最大值
int rowCount = worksheet.getRowCount();
int columnCount = worksheet.getColumnCount();
for (int i = 0; i < rowCount; i++) {
// 初始的高度
double height = worksheet.getRange(i, 0).getHeight();
// 初始的宽度
double width = worksheet.getRange(i, 0).getWidth();
if (width < 0 || width > 255) {
continue;
}
for (int i1 = 0; i1 < columnCount; i1++) {
String text = worksheet.getRange(i, i1).getText();
if (StringUtils.isNotEmpty(text)) {
forCalculateSheet.getRange(0, 0).setValue(text);
forCalculateSheet.getRange(0, 0).setColumnWidth(width);
forCalculateSheet.getRange(0, 0).setWrapText(true);
forCalculateSheet.getRange(0, 0).autoFit();
double calculateHeight = forCalculateSheet.getRange(0, 0).getHeight();
height = height > calculateHeight ? height : calculateHeight;
}
}
worksheet.getRange(i, 0).getRows().setWrapText(true);
worksheet.getRange(i, 0).getRows().setRowHeight(height);
}
forCalculateSheet 是
// 用于计算单元格高度
IWorksheet forCalculateSheet = worksheets.add();
|