[ExtJS5 Study Notes] Using sencha extjs 5 grid table to export excel files in java background

Source: Internet
Author: User

[ExtJS5 Study Notes] Using sencha extjs 5 grid table to export excel files in java background

After using the js front-end to export excel last time, another major concern is the background excel export, because I developed and used java, I use apache's open-source project poi to export background excel.

Contents

Download the poi project in this directory and load extjs front-end export settings extjs back-end solutions create an excel Workbook create an excel tab to generate an excel Style and initialize generate a table header row build headers to construct a data row build rows

Download and load poi Projects

The POI project is an open-source project on the apache official website. Its main purpose is to encapsulate microsoft Office software interfaces so that users can write them in encoding mode.
Apache POI: http://poi.apache.org/
When writing an article, the latest version is 3.1.1. After downloading the bin package and decompressing it, add the jar package (the jar package in a piece) to the project lib:
Vc/uxL +/4tbQvs2/ydLUwcuhozwvcD4NCjxoMyBpZD0 = "extjs frontend export Settings"> extjs frontend export settings

Add an export excel button to the gridtoolbar at the bottom of the front-end extjs grid to add an event to be processed and associate the event to the background action.

ExportexyjsGrid: function (grid) {// associate with the background and input required parameters}
Solutions for extjs background

Action processing in the background:

Create an excel Workbook
HSSFWorkbook workbook = new HSSFWorkbook();
Create an excel Tab
HSSFSheet sheet = workbook. createSheet ("tab title ");
Generate an excel Style and initialize it
HSSFCellStyle style = workbook.createCellStyle();
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);    }
Build rows)

Just like the header row, traverse the grid parameters passed in at the front end and find the store filter parameter condition. traverse and insert the excel Data row and fill in the data.

The markdown editor function used in this article is as follows:
1. Code highlighting
2. upload images
3. Title directory

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.