excel

DataRow dr1 = table.NewRow();
dr1.ItemArray = ob;
table.Rows.InsertAt(dr1,0);
System.Text.StringBuilder strb = new StringBuilder();

foreach(DataRow dr in table.Rows)
{
foreach(object obj in dr.ItemArray)
{
strb .Append(obj.ToString()+"\t");
}
strb.Append("\r\n");

}
string filePath = Page.MapPath("");
filePath += "\\readme.xls";
StreamWriter sw = new StreamWriter(filePath,false,System.Text.Encoding.Unicode);
sw.Write(strb.ToString());
sw.Close();
Page.Response.Clear();
// 输入参数 _Request: Page.Request对象, _Response: Page.Response对象, _fileName: 下载文件名, _fullPath: 带文件名下载路径, _speed 每秒允许下载的字节数
//string filePath = Page.MapPath("file.doc");
string fileName = System.IO.Path.GetFileName(filePath);

FlieWown fileDown = new FlieWown();
bool success = fileDown.ResponseFile(Page.Request, Page.Response, fileName, filePath, 1024000);
if(!success)
Response.Write("下载文件出错!");
Page.Response.End();
System.IO.File.Delete(filePath);

你可能感兴趣的:(Excel)