MVC Browser Export Excel file (NPOI)

Source: Internet
Author: User

First, refer to the Npoi. dll

. dll: Link: Https://pan.baidu.com/s/1K4cCb4qpkIfDoH1fZnNvVQ Password: I9SL

There is a Excelhelper helper class, copied to the project, to the method in the Help class to pass the parameters to complete the export

Second, in view: The button jumps directly to which Controller's method (note that the method's return value type is Fileresult)

Third, the code in the Controller method is as follows:

  PublicFileresult Dropfile () {stringSheetName ="Workbook 1";//Set Workbook name            stringDroppath = Server.MapPath (@"\dropexcal\");//Set Save path            if(! Directory.Exists (Droppath))//determine if the path exists{directory.createdirectory (droppath);//does not exist then creates            }            stringFileName ="Excel Data Export"+ SYSTEM.DATETIME.NOW.TOFILETIMEUTC (). ToString () +". xlsx";//set the file name after export            //////////Invoke Helper class//////////DataTable CUSDT = todatatable (list);//calling the Help class to convert the List<t> type to a DataTable typeExportexcel (CUSDT, SheetName,"Customer Data", Droppath + FileName);//call the Help class to save the file in a local folder (the Help class automatically converts the table table to Excel when there are several styles to choose from)            //////////Invoke Helper class//////////            strings = mimemapping.getmimemapping (FileName);//Gets the download content type (MIME type).             returnFile (Droppath + filename, s, path.getfilename (Droppath + filename));//Returns a browser download dialog box (download the saved local file)}

Data format conversions: 6617683 references

Clicking on the download browser will bring up the download prompt box:

MVC Browser Export Excel file (NPOI)

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.