[英]Aspose Sort Cells based on Row as Key in java
I have an Excel File with Some Columns merged as shown in the Screen Shot, I want to Sort the TOP Columns in ascending order and their Corresponding values, and then I'll sort the COLUMN1, COLUMN2, Column3
, But Before I want to Sort the TOP Column Headers, For Eg: TOP COLUMN A
should Come first and the Corresponding Sub column
and the values of those Six TOP columns. 我有一个合并了某些列的Excel文件,如屏幕快照所示,我想按升序及其对应值对TOP列进行排序,然后对
COLUMN1, COLUMN2, Column3
进行排序,但是在我要进行排序之前TOP列标题,例如: TOP COLUMN A
应该排在最前面,相应的Sub column
以及这六个TOP列的值。
Content area I was able to sort, but how will I be able to achieve Sorting for the TOP Cols Headers? 我可以对内容区域进行排序,但是如何实现TOP Cols标头的排序?
Since, you want to sort data from left to right, you need to set the following property to true. 由于要从左到右对数据进行排序,因此需要将以下属性设置为true。
Workbook.getDataSorter().setSortLeftToRight(true);
Please see the following code. 请参见以下代码。 It sorts data from left to right by row 3 .
它按行3从左到右对数据进行排序 。 You can add more levels too.
您也可以添加更多级别。
Java Java的
// Load your Excel file
Workbook wb = new Workbook(dirPath + "sort.xlsx");
// For the first key, we want to sort by assending order
// And we want to sort by row not by column
// using SortLeftToRight property
wb.getDataSorter().setOrder1(SortOrder.ASCENDING);
wb.getDataSorter().setSortLeftToRight(true);
// Access first worksheet
Worksheet ws = wb.getWorksheets().get(0);
// Specify the range of cells
CellArea ca = CellArea.createCellArea("A1", "I7");
// We want to sort by row 3, since index starts from 0
// So 2 means 3
wb.getDataSorter().setKey1(2);
// Sort the workbook data
wb.getDataSorter().sort(ws.getCells(), ca);
// Save the output Excel file
wb.save(dirPath + "output.xlsx");
Note: I am working as Developer Evangelist at Aspose 注意: 我在Aspose担任开发人员布道者
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.