gpt4 book ai didi

JXL 单元格格式

转载 作者:行者123 更新时间:2023-12-03 10:08:21 25 4
gpt4 key购买 nike

如何使用 jxl api 自动调整单元格中的内容?

最佳答案

该方法是不言自明的并评论:

private void sheetAutoFitColumns(WritableSheet sheet) {
for (int i = 0; i < sheet.getColumns(); i++) {
Cell[] cells = sheet.getColumn(i);
int longestStrLen = -1;

if (cells.length == 0)
continue;

/* Find the widest cell in the column. */
for (int j = 0; j < cells.length; j++) {
if ( cells[j].getContents().length() > longestStrLen ) {
String str = cells[j].getContents();
if (str == null || str.isEmpty())
continue;
longestStrLen = str.trim().length();
}
}

/* If not found, skip the column. */
if (longestStrLen == -1)
continue;

/* If wider than the max width, crop width */
if (longestStrLen > 255)
longestStrLen = 255;

CellView cv = sheet.getColumnView(i);
cv.setSize(longestStrLen * 256 + 100); /* Every character is 256 units wide, so scale it. */
sheet.setColumnView(i, cv);
}
}

关于JXL 单元格格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1665391/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com