开发者

JXLS - Column width lost

开发者 https://www.devze.com 2023-02-04 02:01 出处:网络
I am using JXLS to create an Excel sheet. In the templa开发者_StackOverflowte, I have specified the column widths needed for every column. The output was HSSFWorkbook. From the HSSFWorkbook object, I

I am using JXLS to create an Excel sheet. In the templa开发者_StackOverflowte, I have specified the column widths needed for every column. The output was HSSFWorkbook. From the HSSFWorkbook object, I am creating a byte array as shown below. The problem is, I lose the column width.

byte[] bytes = null;
HSSFWorkbook workbook = (HSSFWorkbook) transformer.transformXLS(inputStream, beans);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(1024);
workbook.write(byteArrayOutputStream);
bytes = byteArrayOutputStream.toByteArray();

Any suggestions to fix this issue?

Found the answer. The following part should be placed at the third line.

for(int len = 0; len < 11; len++){
  workbook.getSheetAt(0).setColumnWidth(len, 5200);
}


Found the answer. The following part should be placed at the third line.

for(int len = 0; len < 11; len++){
  workbook.getSheetAt(0).setColumnWidth(len, 5200);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号