相关疑难解决方法(0)

Apache-POI在excel中排序行

我想用一个字符串列对表中的行进行排序.我尝试使用Sheet.shiftRows方法实现这一点,但我无法管理.它不会在我的方法中切换行的位置.我的代码有什么问题?或者也许有更好的方法来排序excel中任何String列的行?

/**
 * Sorts (A-Z) rows by String column
 * @param sheet - sheet to sort
 * @param column - String column to sort by
 * @param rowStart - sorting from this row down
 */
private void sortSheet(Sheet sheet, int column, int rowStart) {
    boolean sorting = true;
    int lastRow = sheet.getLastRowNum();
    while (sorting == true) {
        sorting = false;
        for (Row row : sheet) {
            // skip if this row is before first to sort
            if (row.getRowNum()<rowStart) continue;
            // …
Run Code Online (Sandbox Code Playgroud)

java sorting excel row apache-poi

12
推荐指数
2
解决办法
2万
查看次数

XSSFSheet(Apache POI)排序和过滤

我在XSSFSheet上创建一个自动过滤器,如下所示:

sheet.setAutoFilter(new CellRangeAddress(1, sheet.getLastRowNum() + 1,
                0, 14));
Run Code Online (Sandbox Code Playgroud)

它工作正常,但我也希望它默认按特定列上的升序值排序(第1列从零开始索引).有谁知道怎么做?

谢谢!山姆

java

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

java ×2

apache-poi ×1

excel ×1

row ×1

sorting ×1