我有一个gridview
<asp:GridView ID="gvExportList" AutoGenerateColumns="false" AllowPaging="false" AllowSorting="false" runat="server" HeaderStyle-BackColor="LightGray">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID #" DataFormatString=" {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