Use NPOI to export the information in the database to an Excel table and prompt the user to download it. npoiexcel

Source: Internet
Author: User

Use NPOI to export the information in the database to an Excel table and prompt the user to download it. npoiexcel

You can use NPOI to export an Excel table. On the Internet, I seldom find an Excel table to be exported and prompt to download it.

The simple code is as follows:

1 // The mvc project can pass multiple ids separated by commas (,). string 2 public ActionResult execl (string ids) 3 {4 List <PayLog> list = new List <PayLog> (); 5 string [] idsstring = ids. split (new char [] {','}, StringSplitOptions. removeEmptyEntries); // split string 6 for (int j = 0; j <idsstring. length; j ++) 7 {8 string str = idsstring [j]; 9 list. add (DbSession. payLogRepository. fetch (x => x. FInvoiceId = str); // link to the database to read data objects 10} 11 HSSFWorkbook work = new HSSFWorkbook (); // create page 12 HSSFSheet sheet = work. createSheet (); // create column 13 HSSFRow row = sheet. createRow (0); // The first row 14 row. createCell (0, HSSFCell. CELL_TYPE_STRING ). setCellValue ("Serial Number"); 15 row. createCell (1, HSSFCell. CELL_TYPE_STRING ). setCellValue ("encoding"); 16 // create data column 17 for (int I = 0; I <list. count; I ++) 18 {19 HSSFRow rows = sheet. createRow (I + 1); 20 rows. createCell (0, HSSFCell. CELL_TYPE_STRING ). setCellValue (list [I]. FPayInNo); 21 rows. createCell (1, HSSFCell. CELL_TYPE_STRING ). setCellValue (list [I]. FEnterpriseId); 22} 23 string path = @ "F: \ .xls"; // The relative path instead of the absolute path 24 using (FileStream file = new FileStream (path, FileMode. create) 25 {26 work. write (file); 27} 28 return File (new FileStream (path, FileMode. open), "application/ms-excel", ".xls ");

Result


Net export EXCEL using NPOI, if the corresponding statistical chart is automatically generated

Use the function in the EXCEL template to write the display area! After the Excel file is generated, it will be displayed in statistics!
 
Winform uses NPOI to export the EXCEL file. The column name is fixed. Fill in the data in the excel file.

Here is a self-Summary of helper.



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.