私はグリッドビューのデータをExcelに転送しようとしました....しかし、出力は空白のExcelシートです。どのようにこの問題を解決するには?グリッドビューの値を転送するコードはありますか?データベースを持つシートを秀でる?グリッドビューのデータエクスポートasp.netでExcelに
protected void btnexcel_Click1(object sender, EventArgs e)
{
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
gvdetails.AllowPaging = false;
gvdetails.DataBind();
gvdetails.HeaderRow.Style.Add("background-color", "#FFFFFF");
gvdetails.HeaderRow.Cells[0].Style.Add("background-color", "green");
gvdetails.HeaderRow.Cells[1].Style.Add("background-color", "green");
gvdetails.HeaderRow.Cells[2].Style.Add("background-color", "green");
for (int i = 0; i < gvdetails.Rows.Count;i++)
{
GridViewRow row = gvdetails.Rows[i];
row.BackColor = System.Drawing.Color.White;
row.Attributes.Add("class", "textmode");
if (i % 2 != 0)
{
row.Cells[0].Style.Add("background-color", "#C2D69B");
row.Cells[1].Style.Add("background-color", "#C2D69B");
row.Cells[2].Style.Add("background-color", "#C2D69B");
}
}
string style = @"<style> .textmode { mso-number-format:\@; } </style>";
Response.Write(style);
Response.Output.Write(sw.ToString());
Response.End();
}
? – Ratna
@Ratna:生成中のExcelシートは空白です。要件を正しく読んでください。 – pordi
あなたはこれがexcel exportではないことを知っていることを願っています。あなたは、HTMLテーブルとトリックブラウザに間違ったコンテンツタイプを提供しています。あなたがこのアプローチで得ることができる多くの問題があります。 http://stackoverflow.com/a/10245406/351383 –