2

グリッドビューを MS Word にエクスポートし、グリッドビューのフォーマットを維持する方法はありますか? 以下のコードはグリッドビューをエクスポートするために機能しますが、フォーマットを維持する方法がわかりません。(サードパーティのソフトウェアは使用できません)

    Response.Clear()
    Response.Buffer = True
    Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.doc")
    Response.Charset = ""
    Response.ContentType = "application/vnd.ms-word"

    Dim sw As New StringWriter()
    Dim hw As New HtmlTextWriter(sw)
    GridView1.RenderControl(hw)
    Response.Output.Write(sw.ToString())
    Response.Flush()
    Response.End()
4

3 に答える 3

2

私の最善の推測はclasses、ファイルで定義されたグリッドの色、列の配置などのほとんどを定義していて、CSSエクスポートすると、これらのクラスを参照できなくなるということです。

これを修正するには、インライン スタイルを使用して、レンダリングされた HTML が自己完結型であり、グリッドが Word ドキュメントとして書き込まれたときに色やその他の書式が保持されるようにする必要があります。

于 2012-08-31T20:09:30.743 に答える
0
     >First bind your grid 
     >Response.ClearContent();
       Response.AddHeader("content-disposition", string.Format("attachment; 
       filename={0}", "Customers.doc"));              

     Response.Charset = "";
    Response.ContentType = "application/ms-word";
    StringWriter sw = new StringWriter();
    HtmlTextWriter htw = new HtmlTextWriter(sw);
    GridView1.RenderControl(htw);
    Response.Write(sw.ToString());
    Response.End();
   ><%@ Page Language="C#" AutoEventWireup="true" CodeFile="Records.aspx.cs"  
       Inherits="Records"
     MasterPageFile="~/Master.master"  EnableEventValidation="false" %>
   >use this code if img click event not fired
     protected void mswrd_imgbtn_PreRender(object sender, EventArgs e)
     {
    ImageButton btn = sender as ImageButton;
    ScriptManager sc = ScriptManager.GetCurrent(this.Page);
    sc.RegisterPostBackControl(btn);
     }
于 2014-02-10T11:18:38.217 に答える
0

forums.asp.net からのこのサンプルは、その役割を果たしていると主張しています。

Response.AppendHeader("content-disposition", "attachment;filename=FileEName.doc");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.ms-word";
this.EnableViewState = false;
Response.Write(word.InnerHtml);
Response.End();

http://forums.asp.net/t/1823755.aspx/1

于 2012-08-31T20:07:25.667 に答える