求助:asp网页excel导出,怎么设置为下载方式?
下面这excel导出函数 怎么修改能在页面上下载呢?
求高手帮忙!!!
public void createxcel(System.Data.DataTable datatable, string filename)
{
HttpResponse response;
response = HttpContext.Current.Response;
response.Clear();
response.Buffer = true;
response.Charset = "utf-8";
response.AppendHeader("Content-Disposition", "attachment;filename=" + filename + ".xls");
response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
response.ContentType = "application/ms-excel";
string colheaders = "", ls_items = "";
System.Data.DataTable dt = datatable;
DataRow[] row = dt.Select();
int i = 0;
int cl = dt.Columns.Count;
for (i = 0; i < cl; i++)
{
if (i == cl - 1)
{
colheaders += dt.Columns[i].Caption.ToString() + "\n";
}
else
{
colheaders += dt.Columns[i].Caption.ToString() + "\t";
}
}
response.Write(colheaders);
foreach (DataRow rows in row)
{
for (i = 0; i < cl; i++)
{
if (i == cl)
{
ls_items += rows[i].ToString() + "\n";
}
else
{
ls_items += rows[i].ToString() + "\n";
}
}
response.Write(ls_items);
ls_items = "";
}
response.End();
}
}
[解决办法]
updatepanel里影响