public ActionResult OutPutExcel(string Ids)
{
DataTable dt = new BEnquirePerson().GetOutPutData(Ids);//获取数据源
string FileType = ".xls";//设置文件格式
string FileName = DateTime.Now.ToShortTimeString();
Response.Clear();
Response.Charset = "UTF-8";
Response.Buffer = true;
Response.ContentEncoding = Encoding.GetEncoding("GB2312");
Response.AppendHeader("Content-Disposition", "attachment;filename=\"" + HttpUtility.UrlEncode(FileName, Encoding.UTF8) + ".xls\"");
Response.ContentType = FileType;
string colHeaders = string.Empty;
string ls_item = string.Empty;
if (dt != null && dt.Rows.Count > 0)
{
DataRow[] myRow = dt.Select();
int i = 0;
int cl = dt.Columns.Count;
ls_item += "姓名\t电话\t咨询内容\t所属人\t\n"; //加表头
foreach (DataRow row in myRow)
{
for (i = 0; i < cl; i++)
{
if (i == (cl - 1))
{
ls_item += row[i].ToString() + "\n";
}
else
{
ls_item += row[i].ToString() + "\t";
}
}
Response.Output.Write(ls_item);
ls_item = string.Empty;
}
}
Response.Output.Flush();//导出Excel
Response.End();
return new EmptyResult();
}
{
DataTable dt = new BEnquirePerson().GetOutPutData(Ids);//获取数据源
string FileType = ".xls";//设置文件格式
string FileName = DateTime.Now.ToShortTimeString();
Response.Clear();
Response.Charset = "UTF-8";
Response.Buffer = true;
Response.ContentEncoding = Encoding.GetEncoding("GB2312");
Response.AppendHeader("Content-Disposition", "attachment;filename=\"" + HttpUtility.UrlEncode(FileName, Encoding.UTF8) + ".xls\"");
Response.ContentType = FileType;
string colHeaders = string.Empty;
string ls_item = string.Empty;
if (dt != null && dt.Rows.Count > 0)
{
DataRow[] myRow = dt.Select();
int i = 0;
int cl = dt.Columns.Count;
ls_item += "姓名\t电话\t咨询内容\t所属人\t\n"; //加表头
foreach (DataRow row in myRow)
{
for (i = 0; i < cl; i++)
{
if (i == (cl - 1))
{
ls_item += row[i].ToString() + "\n";
}
else
{
ls_item += row[i].ToString() + "\t";
}
}
Response.Output.Write(ls_item);
ls_item = string.Empty;
}
}
Response.Output.Flush();//导出Excel
Response.End();
return new EmptyResult();
}