我基本上已将以下内容放入我的按钮单击偶数处理程序中,它主要工作但它也在 CSV 文件中写出页面的所有 html。有没有办法阻止这种情况?
StringBuilder sb = new StringBuilder();
sb.AppendLine("pkey,epsn,Cal. Date (UTC),Va Mult, Vb Mult, Vc Mult,Ia Mult, Ib Mult, Ic Mult, Ia Phase, Ib Phase, Ic Phase, CT Rating, CT Type, Cal By");
Response.ContentType = "application/csv";
Response.AddHeader("content-disposition", "attachment; filename=EPSn.csv");
Response.Write(sb.ToString());
foreach (DataRow row in dt.Rows)
{
sb = new StringBuilder((string)row[0]);
for (int i = 1; i < dt.Columns.Count; i++)
{
if (row[i] is DBNull)
sb.Append(",NULL");
else if (i == 2)
sb.Append("," + new DateTime((long)row[i]).ToString("G"));
else
sb.Append("," + row[i].ToString());
}
sb.AppendLine();
Response.Write(sb.ToString());