Using Npoi to export Excel tables Basically, I find it very rare to export Excel forms and prompt them to download.
The simple code is as follows
1 //MVC projects can pass multiple IDs with comma-separated strings2 PublicActionResult Execl (stringIDs)3 {4list<paylog> list =NewList<paylog>();5 string[] idsstring = IDs. Split (New Char[] {','}, Stringsplitoptions.removeemptyentries);//Split String6 for(intj =0; J < Idsstring. Length; J + +)7 {8 stringstr =Idsstring[j];9List. ADD (DbSession.PayLogRepository.Fetch (x = X.finvoiceid = = str));//link Database Read data objectTen } OneHssfworkbook work =NewHssfworkbook ();//Create page AHssfsheet sheet = work. Createsheet ();//Create Columns -Hssfrow row = sheet. CreateRow (0);//First line -Row. Createcell (0, hssfcell.cell_type_string). Setcellvalue ("Serial Number"); theRow. Createcell (1, hssfcell.cell_type_string). Setcellvalue ("Coding"); - //looping object collections creating data Columns - for(inti =0; I < list. Count; i++) - { +Hssfrow rows = Sheet. CreateRow (i +1); -Rows. Createcell (0, hssfcell.cell_type_string). Setcellvalue (List[i]. Fpayinno); +Rows. Createcell (1, hssfcell.cell_type_string). Setcellvalue (List[i]. Fenterpriseid); A } at stringPath =@"f:\ information. xls";//the project should be changed to a relative path instead of an absolute path - using(FileStream file =NewFileStream (path, filemode.create)) - { - Work . Write (file); - } - returnFile (NewFileStream (Path, FileMode.Open),"Application/ms-excel","information. xls");
Results
Use Npoi to export the information in the database to an Excel table and prompt the user to download