java XSSFSheet(Apache POI)排序和筛选
我正在XSSFSheet上创建一个自动过滤器,如下所示:
sheet.setAutoFilter(new CellRangeAddress(1, sheet.getLastRowNum() + 1,
0, 14));
它工作得很好,但我也希望它默认按特定列上的升序值排序(列1从零开始索引)。有人知道怎么做吗
谢谢! 萨姆
你可以在下面搜索框中键入要查询的问题!
我正在XSSFSheet上创建一个自动过滤器,如下所示:
sheet.setAutoFilter(new CellRangeAddress(1, sheet.getLastRowNum() + 1,
0, 14));
它工作得很好,但我也希望它默认按特定列上的升序值排序(列1从零开始索引)。有人知道怎么做吗
谢谢! 萨姆
# 1 楼答案
一,。使用ASPOSE库进行排序
目前,Apache POI没有可用的排序。我建议ApachePOI使用AsposeJava。有了这个库,您的类将如下所示:
参考文献::https://asposeapachepoi.codeplex.com/wikipage?title=Sort%20Data
二,。使用Java集合。排序()
如果你不想或不能像我一样使用ASPOSE,你可以在源文件中创建一个表示数据行的类,它实现了
。用您的条件覆盖方法java.lang.Comparable
,并递增使用compareTo
to sort your list。比如:Collections.sort()
然后,在主类(或要在MyRow列表中对其排序的类)中,您可以编写以下代码: