在IE7、8 FF,都可以,就是在IE6上不行。
我的方法: public void CreateExcel(DataTable dt, string fileName)
{
HttpResponse response = HttpContext.Current.Response;
response.ContentEncoding = Encoding.GetEncoding("GB2312");
response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName);
string s = "";
string str2 = "";
DataRow[] rowArray = dt.Select();
int num = 0;
int count = dt.Columns.Count;
num = 0;
while (num < count)
{
if (num == (count - 1))
{
s = s + dt.Columns[num].Caption.ToString() + "\n";
}
else
{
s = s + dt.Columns[num].Caption.ToString() + "\t";
}
num++;
}
response.Write(s);
foreach (DataRow row in rowArray)
{
for (num = 0; num < count; num++)
{
if (num == (count - 1))
{
str2 = str2 + row[num].ToString() + "\n";
}
else
{
str2 = str2 + row[num].ToString() + "\t";
}
}
response.Write(str2);
str2 = "";
}
response.End();
}
我的方法: public void CreateExcel(DataTable dt, string fileName)
{
HttpResponse response = HttpContext.Current.Response;
response.ContentEncoding = Encoding.GetEncoding("GB2312");
response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName);
string s = "";
string str2 = "";
DataRow[] rowArray = dt.Select();
int num = 0;
int count = dt.Columns.Count;
num = 0;
while (num < count)
{
if (num == (count - 1))
{
s = s + dt.Columns[num].Caption.ToString() + "\n";
}
else
{
s = s + dt.Columns[num].Caption.ToString() + "\t";
}
num++;
}
response.Write(s);
foreach (DataRow row in rowArray)
{
for (num = 0; num < count; num++)
{
if (num == (count - 1))
{
str2 = str2 + row[num].ToString() + "\n";
}
else
{
str2 = str2 + row[num].ToString() + "\t";
}
}
response.Write(str2);
str2 = "";
}
response.End();
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货