How do I use Apache POI to pre-define an auto-filter region in an Excel 2007 document?
A small code example or link would be nice.
I found it difficult to get the CellRange since my columns and row values were both variable. So I used this trick.
Initialize a lastCellReference variable to A1 which is row1, column1 cell
String lastCellReference = "A1";
Everytime you create a cell update the lastCellReference to maintain latest value
cell = row.createCell((short) columnCount);
cell.setCellValue(rs.getInt(i));
lastCellReference=cell.getReference();
A1 will always be first cell and then the lastCellReference
sheet1.setAutoFilter(CellRangeAddress.valueOf("A1:"+ lastCellReference));