导出到excel后要求有字段名怎么操作
导出到excel后要求有字段名如何操作
偶用在这里找的代码实现了导出到excel,但出来的数据没有字段,如何实现导出数据有字段名,谢谢。下面是代码
'导出excel
Dim xlsApp As Excel.Application
xlsApp = Nothing
Dim xlsBook As Excel.Workbook
xlsBook = Nothing
Dim xlsSheet As Excel.Worksheet
xlsSheet = Nothing
Try
xlsApp = New Excel.ApplicationClass
xlsBook = xlsApp.Workbooks.Add(True)
xlsSheet = xlsBook.Worksheets(1)
xlsSheet.Activate()
Catch ex As Exception
Throw New NullReferenceException(ex.Message)
End Try
Dim i, k As Integer
Dim table As DataTable
table = New DataTable( "pizi ")
table = ds.Tables(0)
For i = 0 To table.Rows.Count - 1
For k = 0 To table.Rows(i).ItemArray.Length - 1
xlsApp.Cells(i + 2, k + 1) = table.Rows(i).ItemArray(k)
Next
Next
xlsApp.Visible = True
出来的效果希望能达到:
名称 职位 xxx xxxx xxxxx
张三 职员 ... ... .....
...
谢谢
------解决方案--------------------
还可以用一种比较笨的办法
xlApp.Cells(1, 1) = "名称 "
xlApp.Cells(1, 2) = "职位 "
xlApp.Cells(1, 3) = "**** "
xlApp.Cells(1, 4) = "**** "
xlApp.Cells(1, 5) = "**** "
xlApp.Cells(1, 6) = "**** "
偶用在这里找的代码实现了导出到excel,但出来的数据没有字段,如何实现导出数据有字段名,谢谢。下面是代码
'导出excel
Dim xlsApp As Excel.Application
xlsApp = Nothing
Dim xlsBook As Excel.Workbook
xlsBook = Nothing
Dim xlsSheet As Excel.Worksheet
xlsSheet = Nothing
Try
xlsApp = New Excel.ApplicationClass
xlsBook = xlsApp.Workbooks.Add(True)
xlsSheet = xlsBook.Worksheets(1)
xlsSheet.Activate()
Catch ex As Exception
Throw New NullReferenceException(ex.Message)
End Try
Dim i, k As Integer
Dim table As DataTable
table = New DataTable( "pizi ")
table = ds.Tables(0)
For i = 0 To table.Rows.Count - 1
For k = 0 To table.Rows(i).ItemArray.Length - 1
xlsApp.Cells(i + 2, k + 1) = table.Rows(i).ItemArray(k)
Next
Next
xlsApp.Visible = True
出来的效果希望能达到:
名称 职位 xxx xxxx xxxxx
张三 职员 ... ... .....
...
谢谢
------解决方案--------------------
还可以用一种比较笨的办法
xlApp.Cells(1, 1) = "名称 "
xlApp.Cells(1, 2) = "职位 "
xlApp.Cells(1, 3) = "**** "
xlApp.Cells(1, 4) = "**** "
xlApp.Cells(1, 5) = "**** "
xlApp.Cells(1, 6) = "**** "