Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use ASP.NET to output EXCEL

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report