DataTable pDataTable = newBLL.PRODUCT().GetModel(1862);
inttRowCount = pDataTable.Rows.Count;
inttColumnCount = pDataTable.Columns.Count;
Response.Expires = 0;
Response.Clear();
Response.Buffer = true;
Response.Charset = "utf-8";
Response.ContentEncoding =System.Text.Encoding.UTF8;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment; filename=Excel.xls");
Response.Write("<meta http-equiv=Content-Typecontent=text/html;charset=utf-8>");
Response.Write("<Table borderColor=black border=1>");
Response.Write("\n <TR>");
for(int i = 0; i < tColumnCount; i++)
{
Response.Write("\n <TD bgcolor = #fff8dc>");
Response.Write(pDataTable.Columns[i].ColumnName);
Response.Write("\n </TD>");
}
Response.Write("\n </TR>");
for(int j = 0; j < tRowCount; j++)
{
Response.Write("\n <TR>");
for(int k = 0; k < tColumnCount; k++)
{
Response.Write("\n <TD align=\"right\"style=‘vnd.ms-excel.numberformat:@‘>");
Response.Write(pDataTable.Rows[j][k].ToString());
Response.Write("\n </TD>");
}
Response.Write("\n </TR>");
}
Response.Write("</Table>");
Response.End();
原文地址:http://smileface.blog.51cto.com/5740492/1714695