点击(此处)折叠或打开
-
string fileURL="d://test.xls";
-
System.IO.FileInfo fileInfo = new System.IO.FileInfo(fileURL);
-
Response.Clear();
-
Response.AddHeader("content-disposition", "attachment;filename=" + Server.UrlEncode(fileInfo.Name.ToString()));
-
Response.AddHeader("content-length", fileInfo.Length.ToString());
-
Response.ContentType = "application/octet-stream";
-
Response.Charset = "gb2312";
-
Response.ContentEncoding = Encoding.UTF8;
-
Response.WriteFile(fileURL);
-
Response.Flush();
- Response.End();
2 将流中的数据写入到文件
点击(此处)折叠或打开
-
StringWriter sw = new StringWriter();
-
string str = "12t34t56thah";
-
sw.WriteLine(str);
-
输出到Excel
-
Response.Clear();
-
Response.AddHeader("Content-disposition", "attachment;filename="+filename+".xls");
-
//Response.ContentEncoding = Encoding.GetEncoding("gb2312");
-
Response.ContentEncoding = Encoding.UTF8;
-
Response.ContentType = "application/ms-excel";
-
Response.Charset = "gb2312";
-
Response.Write(sw.ToString());
-
sw.Close();
-
Response.Flush();
- Response.End();