Private objXls As Application
Private objWbk As Workbook
Private objSht As Worksheet
Private objShts As Worksheets
Private sheetname As String
Public Function Open(ByVal strFileName As String) As Boolean
Try
If File.Exists(strFileName) = False Then
Return False
End If
objXls = New Application()
'Visble
objXls.Visible = False
objWbk = objXls.Workbooks.Open(strFileName)
objShts = objWbk.Worksheets()
Return True
Catch ex As Exception
Return False
End Try
End Function
Public Function Add(ByVal strFileName As String) As Boolean
Try
If File.Exists(strFileName) = False Then
Return False
Else
objXls = New Application()
'Visble
objXls.Visible = False
objWbk = objXls.Workbooks.Add(strFileName)
objShts = objWbk.Sheets
Return True
End If
Catch ex As Exception
Return False
End Try
End Function
Public Function GetSheetName() As ListBox
' m_ListBox = m_ComboBox
Return Nothing
End Function
Public Function Save() As Boolean
Try
objWbk.Save()
Return True
Catch ex As Exception
Return False
End Try
End Function
Public Function SaveAs(ByVal filename As String) As Boolean
'40 工作表另存为 myexcel.ActiveWorkbook.saveas("C:\book2.xls")
Try
objWbk.SaveAs(filename)
Catch ex As Exception
Return False
End Try
End Function
Public Function Auto_Save(ByVal filename As String) As Boolean
' Application.DisplayAlerts = False
objXls.DisplayAlerts = False
' ActiveWorkbook.Close(savechanges:=True, Filename:="文件名.xls")
objWbk.Close(SaveChanges:=True)
objXls.DisplayAlerts = True
' Application.DisplayAlerts = True
End Function
Public Function DeleteSheet(ByVal SheetName As String) As Boolean
'objSht = objShts(SheetName)
'objSht.Delete()
With objWbk
objSht = .Sheets(SheetName)
objSht.Delete()
End With
Return True
End Function
Public Function ActiveSheet(ByVal SheetName As String) As Worksheet
'装载激活待复制的页面
End Function
Public Function CopySheet(ByVal SheetName As String) As Worksheet
'复制到另外一个EXCEL里去
End Function
Public Function AddSheet(ByVal SheetName As String) As Worksheet
’直接ADD到另外一个EXCEL里去
End Function
Public Function Close() As Boolean
Try
If Not objSht Is Nothing Then
objSht = Nothing
End If
If Not objWbk Is Nothing Then
objWbk.Close()
End If
If Not objXls Is Nothing Then
objXls.Quit()
End If
Return True
Catch ex As Exception
Return False
End Try
End Function
Public Function GetCellValue(ByVal intShtIdx As Integer, ByVal intRow As Integer, ByVal intCol As Integer) As String
Dim applicationClass As New ApplicationClass
Dim workbook As Microsoft.Office.Interop.Excel.Workbook = Nothing
workbook = applicationClass.Workbooks.Open("路径+文件名 ")
workbook.Sheets(1).Select()
workbook.Sheets(1).Copy(After:=workbook.Sheets(1))
worksheet.SaveAs("路径+文件名 ")
Dim applicationClass As New ApplicationClass
Dim workbook As Microsoft.Office.Interop.Excel.Workbook = Nothing
workbook = applicationClass.Workbooks.Open("路径+文件名 ")
workbook.Sheets(1).Select()
workbook.Sheets(1).Copy(After:=workbook.Sheets(1))
worksheet.SaveAs("路径+文件名 ")
Dim applicationClass As New ApplicationClass
Dim workbook As Microsoft.Office.Interop.Excel.Workbook = Nothing
workbook = applicationClass.Workbooks.Open("路径+文件名 ")
workbook.Sheets(1).Select()
workbook.Sheets(1).Copy(After:=workbook.Sheets(1))
worksheet.SaveAs("路径+文件名 ")