#Region "从Datatable保存到Excel"
Sub SaveToExcel(ByVal dtz As System.Data.DataTable, ByVal dtn As System.Data.DataTable, ByVal dtj As System.Data.DataTable)
Try
Dim xlApp As Excel.Application = New Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheetZ As Excel.Worksheet
Dim xlSheetN As Excel.Worksheet
Dim xlSheetJ As Excel.Worksheet
Dim rowIndexz As Integer = 1
Dim colIndexz As Integer = 0
Dim rowIndexn As Integer = 1
Dim colIndexn As Integer = 0
Dim rowIndexj As Integer = 1
Dim colIndexj As Integer = 0
Dim Colz As DataColumn
Dim Rowz As DataRow
Dim Coln As DataColumn
Dim Rown As DataRow
Dim Colj As DataColumn
Dim Rowj As DataRow
'保存总参数
For Each Colz In dtz.Columns
colIndexz = colIndexz + 1
xlSheetZ.Cells(1, colIndexz) = Colz.ColumnName
Next
'得到的表所有行,赋值给单元格
For Each Rowz In dtz.Rows
rowIndexz = rowIndexz + 1
colIndexz = 0
For Each Colz In dtz.Columns
colIndexz = colIndexz + 1
xlSheetZ.Cells(rowIndexz, colIndexz) = Rowz(Colz.ColumnName)
xlSheetZ.Columns.AutoFit()
Next
Next
xlSheetZ.Name = "总参数"
'xlSheetZ.Save()
'保存风网数据
For Each Coln In dtn.Columns
colIndexn = colIndexn + 1
xlSheetN.Cells(1, colIndexn) = Coln.ColumnName
Next
'得到的表所有行,赋值给单元格
For Each Rown In dtn.Rows
rowIndexn = rowIndexn + 1
colIndexn = 0
For Each Coln In dtn.Columns
colIndexn = colIndexn + 1
xlSheetN.Cells(rowIndexn, colIndexn) = Rown(Coln.ColumnName)
xlSheetN.Columns.AutoFit()
Next
Next
xlSheetN.Name = "风网数据"
'xlSheetN.Save()
'保存节点数据
For Each Colj In dtj.Columns
colIndexj = colIndexj + 1
xlSheetJ.Cells(1, colIndexj) = Colj.ColumnName
Next
'得到的表所有行,赋值给单元格
For Each Rowj In dtj.Rows
rowIndexj = rowIndexj + 1
colIndexj = 0
For Each Colj In dtj.Columns
colIndexj = colIndexj + 1
xlSheetJ.Cells(rowIndexj, colIndexj) = Rowj(Colj.ColumnName)
xlSheetJ.Columns.AutoFit()
Next
Next
xlSheetJ.Name = "节点数据"
'xlSheetJ.Save()
xlBook.SaveAs("基本参数数据")
If MsgBox("文件保存在:" & filename & " 是否查看?", MsgBoxStyle.YesNo, "提示") = MsgBoxResult.Yes Then
xlApp.Visible = True
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
#End Region