1

I need to make text shows nice in xls document. I'm using spring mvc xml view with java. There is code sample:

CellStyle style = workbook.createCellStyle();
HSSFSheet sheet = workbook.createSheet("Test");
sheet.setDefaultColumnWidth(20);
int worCount = 1;
for (Object s : crimeCaseList) {
    HSSFRow nRow = ud.createRow(rowCount++);
    if(s.getClass().getName().equals("java.util.HashMap")) {
       Map<String, Object> map = (HashMap<String,Object>)s;
       nRow.createCell(0).setCellValue((map.get("rowNum")==null)?"":
           map.get("rowNum").toString());
       .....
    }
}

So, I have a lot of columns and there could be much of text. I need to make it look nice. So, when text come to the end of column it needs to be transfer on new line automaticaly and row should be grow according to text length. How can I do it?

Max Husiv
  • 305
  • 1
  • 4
  • 12

1 Answers1

1

may be autoSizeColumn(int) help you. API

Yogesh Prajapati
  • 4,770
  • 2
  • 36
  • 77
  • I tried this before, it didn't help sheet.autoSizeColumn(1); sheet.autoSizeColumn(2); sheet.autoSizeColumn(3); – Max Husiv Aug 18 '14 at 13:35
  • You are right, I have wrote code sheet.autoSizeColumn(1); before filling table, but now I tried to do this after and it works fine. Thanks. – Max Husiv Aug 18 '14 at 13:54