gridview Excel导出中的字符串格式填充

时间:2016-10-18 18:37:11

标签: c# html asp.net vb.net

我有一个gridview

<asp:GridView ID="gvExportList" AutoGenerateColumns="false" AllowPaging="false" AllowSorting="false" runat="server" HeaderStyle-BackColor="LightGray">
        <Columns>
            <asp:BoundField DataField="ID" HeaderText="ID #" DataFormatString="&nbsp;{0}" />
            <asp:BoundField DataField="Date" HeaderText="Date" DataFormatString="{0:MM/dd/yyyy}" />
            <asp:BoundField DataField="Text" HeaderText="Text" />
</Columns>
        </asp:GridView>

和DataTable dtExportList(这就是excel现在的样子)

      ID       |      Date      |                Text                
-------------------------------------------------------------------
      1        |   10/9/2015    | Phone 10/09/2015 Called for assistance Wafa Dev Email
               |                | 10/09/2015 Needed Infos Monis Nasr
------------------------------------------------------------------------------------------
      2        |   11/9/2015    | Phone 11/09/2015 Visit Mark Jay

XLS扩展名添加到HTML文件

        Response.AddHeader("content-disposition", "attachment;                
        filename=HWI_Tickets" & DateTime.Now.ToString("MMddyyy") & ".xls")
        Response.ContentType = "application/vnd.ms-excel"
        Response.Charset = ""

        Dim tw As New System.IO.StringWriter
        Dim hw As New System.Web.UI.HtmlTextWriter(tw)
        Dim dtExportList As New DataTable

        dtExportList = Session("dtExportList")
        gvExportList.DataSource = dtExportList
        gvExportList.DataBind()

        gvExportList.RenderControl(hw)
        Response.Write(tw.ToString())

我希望excel / gridview中的Text列看起来像这样:

      ID       |      Date      |                Text                
-------------------------------------------------------------------
      1        |   10/9/2015    | Phone 10/09/2015 Called for assistance  Wafa Dev
               |                | Email 10/09/2015 Needed Infos           Monis Nasr
------------------------------------------------------------------------------------------
      2        |   11/9/2015    | Phone 11/09/2015 Visit                  Mark Jay

0 个答案:

没有答案