0

画像

グリッドビューから Excel をエクスポートしていますが、適切な形式が得られません。画像はエクセルファイルで表示しています。画像が欲しくないのですが、どうすればよいですか?

ここに私のコードがあります

protected void Export_to_Excel(object sender, EventArgs e)
{
   //System.Diagnostics.Debugger.Break();
    Response.Clear();
    Response.AddHeader("content-disposition", "attachment;filename=vault-extract-nsf.xls");
    Response.ContentType = "application/vnd.xlsx";
    System.IO.StringWriter stringWrite = new System.IO.StringWriter();
    System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
    GridView1.RenderControl(htmlWrite);
    Response.Write(stringWrite.ToString());
    Response.End();
}
4

2 に答える 2

1

私はそれを行い、画像は無視されます。

protected void Export_to_Excel(object sender, EventArgs e)
    {
        //System.Diagnostics.Debugger.Break();
        Response.Clear();
        Response.AddHeader("content-disposition", "attachment;filename=PatientSearchReport.xls");
        Response.ContentType = "application/vnd.xlsx";
        System.IO.StringWriter stringWrite = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);  
        GridView1.RenderControl(htmlWrite);
        string html2 = Regex.Replace(stringWrite.ToString(), @"(<input type=""image""\/?[^>]+>)", @"", RegexOptions.IgnoreCase);
        html2 = Regex.Replace(html2, @"(<input class=""checkbox""\/?[^>]+>)", @"", RegexOptions.IgnoreCase);
        html2 = Regex.Replace(html2, @"(<a \/?[^>]+>)", @"", RegexOptions.IgnoreCase);
        Response.Write(html2.ToString());
        Response.End();
    }
于 2013-11-25T05:47:52.150 に答える
0

あなたはこのようにすることができます

 protected void Export_to_Excel(object sender, EventArgs e)
 {

GridView tmpGrid = new GridView();
// here bind this grid with same datasource which you have used for GridView1 

//System.Diagnostics.Debugger.Break();
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=vault-extract-nsf.xls");
Response.ContentType = "application/vnd.xlsx";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
tmpGrid.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}
于 2013-11-08T13:56:34.167 に答える