--------简单的读取-------------------
Public xlApp As Excel.Application
Public xlBook As Excel.Workbook
Public xlSheet As Excel.Worksheet
Public Sub OpenExcel()
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("C:/Calender.xls")
Set xlSheet = xlBook.Worksheets(1)
End Sub
Public Sub OpenExcel()
ReadedString =xlSheet.Cells(x, y)
End Sub
Public Sub CloseExcel()
xlBook.Close (False)
xlApp.Application.Quit
Set xlApp = Nothing
End Sub
--------以下为导出(包括各种判断)------------------
g_ExcelSavePath ' 保存路径
g_ExcelFileName '文件名 eg:xx.csv xxx.xls
"判断是否存在,覆盖?
If Dir(g_ExcelSavePath & g_ExcelFileName) <> "" Then
If MsgBox("文件:" & " " & g_ExcelSavePath & g_ExcelFileName & " " & "既在。覆盖?", vbQuestion + vbOKCancel + vbDefaultButton2, "XXXシステム") = vbCancel Then
Exit Sub
Else
Kill (g_ExcelSavePath & g_ExcelFileName)
End If
End If
"判断是否打开
If ExcelIsOpen(g_ExcelFileName) = True Then 'Excel is Open
modGlobal.MsgBoxShow.ShowReturnFalse "MakerPrint", "6009"
Exit Sub
End If
'定义
Dim CurrentApp As Excel.Application
Dim CurrentBook As Excel.Workbook
Dim CurrentSheet As Excel.Worksheet
Dim CurrentQuery As Excel.QueryTable
strExcelFielName = g_ExcelSavePath & g_ExcelFileName
If CurrentApp Is Nothing Then
Set CurrentApp = CreateObject("Excel.Application")
End If
If Dir(strExcelFielName) = "" Then
Set CurrentBook = CurrentApp.Workbooks.Add
CurrentBook.SaveAs strExcelFielName
Else
Kill (strExcelFielName)
Set CurrentBook = CurrentApp.Workbooks.Add
CurrentBook.SaveAs strExcelFielName
End If
CurrentApp.Visible = False
CurrentApp.DisplayAlerts = False '保存,退出时候不弹出警告
CurrentSheet.Name = strMakerName
CurrentBook.Close True
' CurrentBook.Save
CurrentApp.DisplayAlerts = True
CurrentApp.Quit
Set CurrentQuery = Nothing
Set CurrentSheet = Nothing
Set CurrentBook = Nothing
Set CurrentApp = Nothing