After the last use of the JS front-end export of Excel, another major concern is the background implementation of the export Excel, because I developed the use of Java so here using Apache Open Source project poi for the background Excel export.
This document folder
-
- This document folder
- POI Item Download and onboarding
- ExtJS Front-End export settings
- ExtJS the corresponding solution in the background
- Create an Excel workbook
- Create an Excel tab
- Generate an Excel style and initialize
- Generate table header row build headers
- Construct data row Build rows
POI Item Download and onboarding
The POI project is an open source project on the Apache website, and its main purpose is to encapsulate Microsoft's Office software so that users can write it in a coded manner.
Project Open Source URL: Apache poi:http://poi.apache.org/
By the time the article was written, the latest version number was 3.1.1. After the download bin package is decompressed, add the jar package (jar package in the image below) to the project Lib:
Ok. Self-test whether the normal increase in the project library will be able to.
ExtJS Front-End export settings
Adding the bottom gridtoolbar content in the front-end ExtJS Grid Adds an export Excelbutton, adds processing events, and associates the processing event to the background action.
exportexyjsGrid: function (grid) {//关联后台,传入须要的參数}
ExtJS the corresponding solution in the background
Action handling in the background:
Create an Excel workbook
HSSFWorkbook workbook = new HSSFWorkbook();
Create an Excel tab
HSSFSheet sheet = workbook.createSheet("页签标题");
Generate an Excel style and initialize
HSSFCellStyle style = workbook.createCellStyle();
Generate table header row (build headers)
HSSFRow row = sheet.createRow(0); for (int i = 0; i < headers.length; i++) { HSSFCell cell = row.createCell(i); cell.setCellStyle(style); HSSFRichTextString text = new HSSFRichTextString(headers[i]); cell.setCellValue(text); }
Constructing data rows (build rows)
As with the header row, traverse the foreground incoming grid argument to find the store filter parameters to traverse the inserted Excel data row and populate the data.
This article mainly uses the Markdown editor function:
1. Code highlighting
2. Image upload
3. Title Folder
[ExtJS5 Study notes] 34th section Sencha ExtJS 5 grid table Java Background export Excel