java xssfsheet_java – XSSFSheet(Apache POI)排序和过滤

1.使用ASPOSE库排序

目前,Apache POI没有可用的排序.我建议ASPOSE Java用于Apache POI.使用该库,您的课程将如下所示:

//Obtain the DataSorter object in the workbook

DataSorter sorter = workbook.getDataSorter();

//Set the first order

sorter.setOrder1(SortOrder.ASCENDING);

//Define the first key.

sorter.setKey1(0);

//Set the second order

sorter.setOrder2(SortOrder.ASCENDING);

//Define the second key

sorter.setKey2(1);

//Create a cells area (range).

CellArea ca = new CellArea();

//Specify the start row index.

ca.StartRow = 1;

//Specify the start column index.

ca.StartColumn = 0;

//Specify the last row index.

ca.EndRow = 9;

//Specify the last column index.

ca.EndColumn = 2;

//Sort data in the specified data range (A2:C10)

sorter.sort(cells, ca);

2.使用Java Collections.sort()

如果您不想或不能像我一样使用ASPOSE,您可以创建一个表示源文件中的数据行的类,该类实现java.lang.Comparable.覆盖方法compareTo和您的条件,并使用Collections.sort()to sort your list递增.像这样的东西:

//imports omitted

public class MyRow implements Comparable{

private String column1;

private int column2;

@Override

public int compareTo(MyRow o) {

return this.column1.compareTo(o.column2);

}

}

然后,在您的主类(或您想要对MyRow列表进行排序的类)中,您将编写代码:

Collections.sort(yourList);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值