This article briefly introduces how to export the Excel Code from Grid. For more information, see.
After reading the FineUI Implementation Method for exporting Grid to Excel, it is actually very simple. It seems that it is very difficult to change one idea.
1. Aspx background code outputs Content Type information
The Code is as follows: |
Copy code |
Response. ClearContent (); Response. AddHeader ("content-disposition", "attachment; filename=MyExcelFile.xls "); Response. ContentType = "application/excel "; Response. Write (GetGridTableHtml (Grid1 )); Response. End (); 2. Directly output Html code Response. Write (@" <Table border = "1"> <Tr> <Td> Excel </td> <Td> By Html </td> </Tr> </Table> ") |
This implementation is sufficient for simply exporting data to Excel.
Easy to use
The introduction of bootstrap. js and the export-all.js In the compressed package can be used.
For details, refer to main. js (the following is to specify a toolbar as xtype: 'exporterclick' when defining the Grid ')
The Code is as follows: |
Copy code |
Height: 350, Width: 600, Title: 'array grid ', RenderTo: 'grid-example ', ViewConfig :{ StripeRows: true }, DockedItems :[ { Xtype: 'toolbar ', Dock: 'top ', Items :[ { Xtype: 'exporterclick ', Store: myStore // The following two configurations have been configured in Buttion. js. The default path does not need to be specified repeatedly. // SwfPath: './downloadify.swf ', // DownloadImage: './download.png ', // Here you can customize the exported file name based on the table. // DownloadName: 'exported Excel name' } ] } ] |