0

グリッド テーブルを Excel に追加し、ヘッダーを Excel に追加しています。

     string subject = lbl_Subj.Text;
    Response.Clear();
    Response.Buffer = true;
    Response.ClearHeaders();
    Response.AddHeader("Cache-Control", "no-store, no-cache");        
    Response.AddHeader("content-disposition", "attachment;filename=" + subject + "-Status");
    Response.Charset = "";
    this.EnableViewState = false;    
    Response.ContentType = "application/vnd.ms-excel";
    System.IO.StringWriter stringWrite = new System.IO.StringWriter();
    System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
    Grid_UserTable.RenderControl(htmlWrite);        
    rptList.RenderControl(htmlWrite);       
    Response.Write(stringWrite.ToString());     
    Response.End();

Excelにテキストを追加するにはどうすればよいですか。次のような文字列を追加したい

string add="this is the text I want to add to the excel";
4

4 に答える 4

2

追加してみてください:htmlWrite.WriteLine(add);

  string subject = lbl_Subj.Text;
    Response.Clear();
    Response.Buffer = true;
    Response.ClearHeaders();
    Response.AddHeader("Cache-Control", "no-store, no-cache");        
    Response.AddHeader("content-disposition", "attachment;filename=" + subject + "-Status");
    Response.Charset = "";
    this.EnableViewState = false;    
    Response.ContentType = "application/vnd.ms-excel";
    System.IO.StringWriter stringWrite = new System.IO.StringWriter();
    System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

    htmlWrite.WriteLine(add);

    Grid_UserTable.RenderControl(htmlWrite);        
    rptList.RenderControl(htmlWrite);       
    Response.Write(stringWrite.ToString());     
    Response.End();
于 2012-03-14T08:33:52.720 に答える
0

Office 2007/2010 を使用している限り、Office Open XML を使用できます - http://msdn.microsoft.com/en-us/office/ee358824

よろしく、 ニティン・ラストギ

于 2011-11-28T11:38:49.993 に答える
0

エクセルはバイナリなので文字列/htmlライターは使えません。

Excel PIA を使用して Excel シートを作成する必要があります。

http://msdn.microsoft.com/en-us/library/ff597926.aspx

于 2011-11-28T11:40:04.977 に答える
0
hw.RenderBeginTag("strong");
hw.Write("this is the text I want to add to the excel" + DateTime.Now);
hw.RenderEndTag();

何か助けが必要な場合はお知らせください..

于 2014-06-27T08:37:47.427 に答える