|
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim xlsheet2 As Excel.Worksheet
Dim ix As Integer = 1 : Dim iy As Integer = 1 : Dim iz As Integer = 1
xlApp = CreateObject("Excel.Application") '创建EXCEL对象
xlBook = xlApp.Workbooks.Open(Application.StartupPath + "\name-id-cell-engine原则.xlsx") '打开原则对照表,写入内存
xlApp.DisplayAlerts = False
xlApp.Visible = False '设置不可见
xlSheet = xlBook.Worksheets(1) '设置当前sheet
Do Until xlSheet.Cells(ix, 1).value = Nothing '判断非空的终极版本
ix += 1
Loop : ix -= 1
howmanyrole = ix - 1 '多少条规则写入全局变量
MsgBox(howmanyrole, vbOKOnly, "通知")
ReDim getcod2(ix - 2, 1) '
For iy = 2 To ix
getcod2(iy - 2, 0) = xlSheet.Cells(iy, 1).value
getcod2(iy - 2, 1) = xlSheet.Cells(iy, 3).value
Next iy '写入完毕
'======================================分割线=============================================================================================
xlSheet = xlBook.Worksheets(2) '再接着写入发动机的原则
ix = 1
Do Until xlSheet.Cells(ix, 1).value = Nothing '判断非空的终极版本
ix += 1
Loop : ix -= 1
howmanyeng = ix - 1 '赋值给全局变量,供其他函数使用
ReDim Engine(ix - 2, 17)
For iy = 1 To ix - 1
For iz = 1 To 17
' Engine(iy, iz) = Trim(xlSheet2.cells(iy + 1, iz))
Engine(iy - 1, iz - 1) = xlSheet.Cells(iy + 1, iz).value '一定要加上父对象xlApp,否则程序无法在进程中结束excel
Next iz
Engine(iy - 1, 17) = xlSheet.Cells(iy + 1, 18).value
Next iy
'发动机原则写入完毕()
'===============================释放所有excel对象================================================================
xlBook.Close(True)
xlApp.Quit() '关闭excel
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp) '释放xlapp
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook) '释放xlbook
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet) '释放xlsheet
GC.Collect() '回收处理
GC.WaitForPendingFinalizers()
xlSheet = Nothing
xlBook = Nothing
xlApp = Nothing '释放EXCEL对象22
'==============================释放完毕==========================================================================
'MsgBox(Engine(3, 12), vbOKOnly, "来自程序的提示!")
End Sub
|
|