POI Auto Filter

前端 未结 6 790
逝去的感伤
逝去的感伤 2021-02-13 16:36

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.

6条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-13 17:13

    Save the first and the last cell from the filter area, and execute:

    sheet.setAutoFilter(new CellRangeAddress(firstCell.getRow(), lastCell.getRow(), firstCell.getCol(), lastCell.getCol()));
    

    For example, from the sheet below.

    >x         (x, y)
      0123456  
    0|--hhh--|   h = header
    1|--+++--|   + = values
    2|--+++--|   - = empty fields
    3|--+++--|
    4|-------|
    

    fist cell will be the header above the first + (2,1) cell. The the last will be the last + cell (5,3)

提交回复
热议问题