使用 XSSF 下载带有 Java 排序列的 xlsx 文件
在我的应用程序中,用户可以下载 xlsx,但现在我想按“供应商”列的字母顺序和“ETD”列的升序日期对该文件进行排序。
我有一个方法来创建我的 xlsx 文件:
public XSSFWorkbook createCalendarExcelFile(final List<CalendarDTO> calendars, final User user) {
final XSSFWorkbook workbook = new XSSFWorkbook();
final SimpleDateFormat sdf = new SimpleDateFormat(DD_MM_YYYY);
final XSSFCellStyle borderStyle = ExcelUtils.createBorderStyle(workbook, BORDER_THIN);
final XSSFFont boldFont = ExcelUtils.createFontStyle(workbook, BOLDWEIGHT_BOLD);
final XSSFFont normalFont = ExcelUtils.createFontStyle(workbook, BOLDWEIGHT_NORMAL);
final XSSFSheet sheet = workbook.createSheet();
final XSSFRow headerRow = sheet.createRow(0);
int headerIndex = 0;
//Header
this.createTabColumn(headerRow, headerIndex++, ORDER_TYPE, boldFont, borderStyle);
this.createTabColumn(headerRow, headerIndex++, ORDER_SUBTYPE, boldFont, borderStyle);
this.createTabColumn(headerRow, headerIndex++, FILE, boldFont, borderStyle);
this.createTabColumn(headerRow, headerIndex++, SUPPLIER_ID + SPACE + HYPHEN + SPACE + NAME, boldFont, borderStyle);
if (CoAndGoConstants.BU_PROFILE.equals(user.getRole().getProfile().getName())) {
this.createTabColumn(headerRow, headerIndex++, DEADLINE, boldFont, borderStyle);
} else {
this.createTabColumn(headerRow, headerIndex++, FIRST_DEADLINE, boldFont, borderStyle);
this.createTabColumn(headerRow, headerIndex++, FINAL_DEADLINE, boldFont, borderStyle);
}
this.createTabColumn(headerRow, headerIndex++, DELAY_REASON, boldFont, borderStyle);
this.createTabColumn(headerRow, headerIndex++, ETD, boldFont, borderStyle);
等等,我用一些流和循环填充它。 (超过 200 行,所以我无法将所有内容粘贴到此处)并且一切都按我想要的方式工作。
但现在我找不到一种方法,可以在用户下载之前按“供应商”列的字母顺序和“ETD”列的升序日期来参数“自动排序”。
如果我不使用外部库会更好。
泰。
In my app, users can download an xlsx but now i want to sort this file by alphabetic order for the column 'Supplier' AND by Ascending date for the column 'ETD'.
I have a method to create my xlsx file :
public XSSFWorkbook createCalendarExcelFile(final List<CalendarDTO> calendars, final User user) {
final XSSFWorkbook workbook = new XSSFWorkbook();
final SimpleDateFormat sdf = new SimpleDateFormat(DD_MM_YYYY);
final XSSFCellStyle borderStyle = ExcelUtils.createBorderStyle(workbook, BORDER_THIN);
final XSSFFont boldFont = ExcelUtils.createFontStyle(workbook, BOLDWEIGHT_BOLD);
final XSSFFont normalFont = ExcelUtils.createFontStyle(workbook, BOLDWEIGHT_NORMAL);
final XSSFSheet sheet = workbook.createSheet();
final XSSFRow headerRow = sheet.createRow(0);
int headerIndex = 0;
//Header
this.createTabColumn(headerRow, headerIndex++, ORDER_TYPE, boldFont, borderStyle);
this.createTabColumn(headerRow, headerIndex++, ORDER_SUBTYPE, boldFont, borderStyle);
this.createTabColumn(headerRow, headerIndex++, FILE, boldFont, borderStyle);
this.createTabColumn(headerRow, headerIndex++, SUPPLIER_ID + SPACE + HYPHEN + SPACE + NAME, boldFont, borderStyle);
if (CoAndGoConstants.BU_PROFILE.equals(user.getRole().getProfile().getName())) {
this.createTabColumn(headerRow, headerIndex++, DEADLINE, boldFont, borderStyle);
} else {
this.createTabColumn(headerRow, headerIndex++, FIRST_DEADLINE, boldFont, borderStyle);
this.createTabColumn(headerRow, headerIndex++, FINAL_DEADLINE, boldFont, borderStyle);
}
this.createTabColumn(headerRow, headerIndex++, DELAY_REASON, boldFont, borderStyle);
this.createTabColumn(headerRow, headerIndex++, ETD, boldFont, borderStyle);
etc etc, and i fill it with some streams and loop. (More than 200 rows, so i can not paste everything here) and everything works as i wanted.
But now i could not find a way to parameter the "auto-sort" by alphabetic order for the column 'Supplier' and Ascending date for the column 'ETD' before the download by users.
it's better if i do not use an external library.
Ty.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 ORDER BY 从数据库中获取排序后的数据
You can get the sorted data from database using ORDER BY