string msg = "ccccccccccccc";
byte[] fileBuffer = new byte[8000];
char[] ch = msg.ToCharArray();
fileBuffer = System.Text.Encoding.Default.GetBytes(ch);
Context.Response.ContentType = "application/vnd.ms-excel";
Context.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("hello.xls", System.Text.Encoding.UTF8));
Context.Response.BinaryWrite(fileBuffer);
Context.Response.End();
Context.Response.Close();
byte[] fileBuffer = new byte[8000];
char[] ch = msg.ToCharArray();
fileBuffer = System.Text.Encoding.Default.GetBytes(ch);
Context.Response.ContentType = "application/vnd.ms-excel";
Context.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("hello.xls", System.Text.Encoding.UTF8));
Context.Response.BinaryWrite(fileBuffer);
Context.Response.End();
Context.Response.Close();
本文展示了一段使用ASP.NET将字符串数据转换为Excel文件并提供下载的代码示例。该示例首先将字符串转换为字符数组,接着利用System.Text.Encoding.Default.GetBytes方法将其编码为字节数组,最后设置HTTP响应头,使客户端能够下载名为hello.xls的Excel文件。
4333

被折叠的 条评论
为什么被折叠?



