基本的に、DataTable の列と行をループして、それらを応答に出力する必要があります。 このリンク 方法を示します。
C# の場合:
DataTable dt =GetData(); string attachment ="添付ファイル; filename=Employee.xls"; Response.ClearContent(); Response.AddHeader("content-disposition", attachment); Response.ContentType ="application/vnd.ms-excel";文字列タブ =""; foreach (dt.Columns の DataColumn dc) { Response.Write(tab + dc.ColumnName);タブ ="\t"; } Response.Write("\n"); int i; foreach (dt.Rows の DataRow dr) { tab =""; for (i =0; i プレ>
VB.NET で
Dim dt As DataTable =GetData() Dim attachment As String ="attachment; filename=Employee.xls" Response.ClearContent() Response.AddHeader("content-disposition", attachment) Response.ContentType =" application/vnd.ms-excel" Dim tab As String ="" For Each dc As DataColumn In dt.Columns Response.Write(tab + dc.ColumnName) tab =vbTab Next Response.Write(vbLf) Dim i As Integer For Each dr As DataRow In dt.Rows tab ="" For i =0 To dt.Columns.Count - 1 Response.Write(tab &dr(i).ToString()) tab =vbTab Next Response.Write(vbLf) Next Response .End()コード> プレ>