Как преобразовать datatable в XML
Private Sub DatatableXml(ByVal dtTemp As DataTable) Dim _excel As New Microsoft.Office.Interop.Excel.Application Dim wBook As Microsoft.Office.Interop.Excel.Workbook Dim wSheet As Microsoft.Office.Interop.Excel.Worksheet wBook = _excel.Workbooks.Add() wSheet = wBook.ActiveSheet() Dim dt As System.Data.DataTable = dtTemp Dim dc As System.Data.DataColumn Dim dr As System.Data.DataRow Dim colIndex As Integer = 0 Dim rowIndex As Integer = 0 For Each dc In dt.Columns colIndex = colIndex + 1 _excel.Cells(1, colIndex) = dc.ColumnName Next For Each dr In dt.Rows rowIndex = rowIndex + 1 colIndex = 0 For Each dc In dt.Columns colIndex = colIndex + 1 _excel.Cells(rowIndex + 1, colIndex) = dr(dc.ColumnName) Next Next wSheet.Columns.AutoFit() Dim strFileName As String = "DataTable.xlsx" If System.IO.File.Exists(strFileName) Then System.IO.File.Delete(strFileName) End If wBook.SaveAs("DataTable.xlsx") wBook.Close() _excel.Quit() End Sub
Что я уже пробовал:
следующая команда сохранит таблицу дат в excel
теперь как преобразовать datatable в xml
на первом ряду как элемент теги