[ExtJS5 Study notes] 34th section Sencha ExtJS 5 grid table Java Background export Excel

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.