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