After the last use of the JS front-end export of Excel, there is a major concern is the background implementation of export Excel, because I developed the use of Java so here using Apache Open Source project poi for the background Excel export.
Directory of this document
-
- Directory of this document
- POI Item Download and load
- ExtJS Front-End export settings
- ExtJS Solutions for the backend
- 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 load
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/
To write the article, the latest version is 3.1.1, download the bin package after extracting the jar package (the jar package in the chip) into the project Lib:
Ok. Test it yourself and add it to the project library as you normally would.
ExtJS Front-End export settings
Adding the bottom gridtoolbar content to the front-end ExtJS grid adds an export Excel button that adds processing events and associates the handle event to the background action.
exportexyjsGrid: function (grid) {//关联后台,传入需要的参数}
ExtJS Solutions for the backend
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 parameter to find the store filter parameters condition traversal Insert the Excel data row and populate the data.
This article mainly uses the Markdown editor function:
1. Code highlighting
2. Image upload
3. Title Catalogue
[ExtJS5 Study notes] section 34th Sencha ExtJS 5 grid table Java Background export Excel