Win a copy of Classic Computer Science Problems in Swift this week in the iOS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to format a column not a cell in POI hssf  RSS feed

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to format a column not a cell. The only way I can figure out how to format a column is by formating each individual cell; by implementing the code listed below. I would like to format a column instead of a row. I am able format a column in excel. I have hundreds/thousands of rows of data to format. Any suggestions would be very much appreciated.

Thanks, Lisa

HSSFCellStyle cellStyle = wb.createCellStyle();
HSSFDataFormat dataFormat = wb.createDataFormat();
cellStyle.setDataFormat(dataFormat.getFormat("0.00"));

HSSFRow row = sheet.createRow(iRow);
HSSFCell cell = row.createCell((short)1);
cell.setCellStyle(cellStyle);
 
Rancher
Posts: 42975
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a weakness of POI: it offers row-oriented functionality, but nothing that's column-oriented. But applying the same formatting for each cell in a column only takes a simple loop with 3 lines of code, so it shouldn't be too bad.
 
Lisa Zapson
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I try to format cells in over 500 rows I get an Excel error and Excel removes some formatting to avoid corrupting the workbook.

If you have any other suggestions I would be very interested.

Thanks, Lisa
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!