I generate a sheet, pretty bog standard headers and columns of data.
I want to turn on the "Filter" function for the sheet, so the user can easily sort and filter the data.
Can I so this using POI?
In Excel, you can create three kinds of filters: by values, by a format, or by criteria. But each of these filter types is mutually exclusive. For example, you can filter by cell color or by a list of numbers, but not by both. You can filter by icon or by a custom filter, but not by both.
Save the first and last cell from filter area, and execute:
sheet.setAutoFilter(new CellRangeAddress(firstCell.getRow(), lastCell.getRow(), firstCell.getCol(), lastCell.getCol()));
For example, from the below sheet.
>x (x, y) 0123456 0|--hhh--| h = header 1|--+++--| + = values 2|--+++--| - = empty fields 3|--+++--| 4|-------|
first cell will be the header above the first +
(2,1) cell. The last will be the last +
cell (5,3)
easiest way of adding filter on header :
sheet.setAutoFilter(new CellRangeAddress(0, 0, 0, numColumns)); sheet.createFreezePane(0, 1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With