通过 POI 在 Excel 工作表的标题上设置过滤器 [英] Setting filter on headers of an Excel sheet via POI

查看:31
本文介绍了通过 POI 在 Excel 工作表的标题上设置过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我生成了一张工作表、漂亮的标准标题和数据列.

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.

我可以使用 POI 这样做吗?

Can I so this using POI?

推荐答案

保存过滤区域的第一个和最后一个单元格,并执行:

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|-------|

第一个单元格将是第一个 + (2,1) 单元格上方的标题.最后将是最后一个 + 单元格 (5,3)

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

这篇关于通过 POI 在 Excel 工作表的标题上设置过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆