0
我想從DataTable使用Response.Write將數據導出到excel文件。 但是,一些數據從excel文件中丟失。可以幫我解決這個問題。 我已經嘗試使用StringBuilder創建html並且循環沒有錯誤,可以獲取所有數據,只有當導出爲excel時纔會丟失。請幫我解決一下這個。Response.Write丟失元素
Response.Buffer = true;
Response.ClearContent();
Response.Write(HEADER);
Response.Write(STYLE);
Response.Write("</head><body><table border=\"0\" style=\"font-size:11pt\"><tr>");
Response.AddHeader("content-disposition", attachment);
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
Response.Write(strTitle);
Response.Write("</tr>");
Response.Write("<tr><td colspan=3>From Date: " + lblFromDate.Text + " To: " + lblToDate.Text + "</td></tr>");
Response.Write("<tr><td colspan=9>Protocol: " + lblProtocol.Text + "</td></tr>");
Response.Write("<tr><td colspan=9>Production Line: " + lblPL.Text + "</td></tr>");
Response.Write("<tr></tr></table>");
Response.Write("<table border=\"1\" style=\"font-size:11pt\">");
Response.Write("<tr>");
for (int i = 0; i < summaryreporttable.Columns.Count - 2; i++)
{
Response.Write(" <th>" + summaryreporttable.Columns[i].ToString() + "</th>");
}
Response.Write("</tr>");
for (int r = 0; r < summaryreporttable.Rows.Count; r++)
{
Response.Write("<tr>");
Response.Write("<td>"+r+"</td>");
for (int i = 0; i < summaryreporttable.Columns.Count - 2; i++)
{
if (summaryreporttable.Columns[i].ToString() == "Issue Date")
{
//Response.Write("<td class=\"x167\" valign=\"top\">" + summaryreporttable.Rows[r][i] + "</td>");
Response.Write(String.Format("<td class=\"x167\" valign=\"top\"> {0} </td>", summaryreporttable.Rows[r][i]));
}
else
{
//Response.Write("<td class=\"x169\" valign=\"top\">" + summaryreporttable.Rows[r][i] + "</td>");
Response.Write(String.Format("<td class=\"x169\" valign=\"top\"> {0} </td>", summaryreporttable.Rows[r][i]));
}
}
Response.Write("</tr>");
Response.Flush();
}
Response.Write("</table></body></html>");
}
catch (Exception ex)
{
}
finally
{
Response.End();
}
正如您所看到的,兩者之間的數據缺失。