c#--two ways to download templates

Source: Internet
Author: User

Here are two ways to download the template, the first is to use the FileStream file stream to load the fixed template, the second is the use of Npol automatically generated template

Using FileStream:

Front-End Requests:

window.open ('/controller/downtemplate ', ' _blank ')

Back-end response:

Public Filestreamresult downtemplate ()
{
FileStream stream = new FileStream (Path.Combine (Server.MapPath (". \\ExcelTemplate ")," * * * import template. xlsx "), FileMode.Open, FileAccess.Read); Find a template under a path
Return File (Stream, "Application/x-excel", "* * * import template. xlsx");
}

Using Npol:

Public Actionresultdowntemplate ()
{

#region Get download list name Data dic

list<dictionary<string, string>> dic = new list<dictionary<string, string>> ();

.....................

.....................

#endregion

Writetoexceldynamic ("", DiC, HttpContext, "* * *" Import template + DateTime.Now.ToString ("yyyyMMdd") + ". xls");
Return Content ("");

}

public void Writetoexceldynamic (string title, list<dictionary<string, string>> data, httpcontextbase Context, String fileName, string[] column)
{
Excelreader.rendertoexceldynamic (title, data, context, fileName, column); The method here is similar to the previous one
}

c#--two ways to download templates

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.