How to use ASP.NET to output EXCEL
How to use ASP.NET output EXCEL, many novices are not very clear about this, in order to help you solve this problem, the following small series will explain in detail for everyone, there are people who need this to learn, I hope you can gain something.
ASP.NET Output EXCEL
In the development of ISO file management system, I have encountered the need to directly output ASPX to EXCEL, and now I will share my experience with you. In fact, the use of ASP.NET output EXCEL, WORD, TXT, HTM and other types of documents is very easy. There are three main steps to complete.
1. Define document type and character encoding
Response.Clear();
Response.Buffer= true;
Response.Charset="utf-8";
//The following line is very important. The attachment parameter indicates that it is downloaded as an attachment. You can change it to online and open it online.
//filename=FileFlow.xls Specifies the name of the output file, noting that its extension matches the specified file type,
It can be: .doc|| .xls || .txt ||.htm
Response.AppendHeader("Content-Disposition","attachment;filename=FileFlow.xls");
Response.ContentEncoding=System.Text.Encoding.GetEncoding("utf-8");
//Response.ContentType Specifies file type can be application/ms-excel||
application/ms-word || application/ms-txt || application/ms-html ||
Or other browsers can support documents directly
Response.ContentType = "application/ms-excel";
this.EnableViewState = false;
Second, define an input stream
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.
HtmlTextWriter(oStringWriter);
III. Binding the target data to the input stream output
this.RenderControl(oHtmlTextWriter); //this means output this page, you can also bind datagrid, or other controls that support obj.RenderControl() properties Response.Write(oStringWriter.ToString()); Response.End();
Summary: This routine in Microsoft Visual Studio. NET 2003 platform test through, applicable to C#and VB, when VB will be used when the keyword changed to me
Did reading the above help you? If you still want to have further understanding of related knowledge or read more related articles, please pay attention to the industry information channel, thank you for your support.