?'文件打開窗口操作
Public CommonDialog1Open As System.Windows.Forms.OpenFileDialog
Dim intErrNum As Short
CommonDialog1Open.FileName = ""
CommonDialog1Save.FileName = ""
CommonDialog1Open.Filter = "EXCEL | *.xls"
CommonDialog1Save.Filter = "EXCEL | *.xls"
CommonDialog1Save.OverwritePrompt = True
CommonDialog1Open.ShowDialog()
CommonDialog1Save.FileName = CommonDialog1Open.FileName
intErrNum = Err.Number
If intErrNum <> Windows.Forms.DialogResult.Cancel Then
'或者寫成下面的方式
'If OpenDialog.ShowDialog() = DialogResult.OK Then
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
txtExcelName.Text = CommonDialog1Open.FileName
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
End If
?
?'Excel操作,可能參照中要增加excel類
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As New Object
Dim WSheetCount As Integer
oExcel = CreateObject("Excel.Application")
oBook = oExcel.Workbooks.Open(txtExcelName.Text, ReadOnly:=True)
WSheetCount = oExcel.ActiveWorkbook.sheets.count
For i = 1 To WSheetCount
’對Sheet1進(jìn)行操作
If oBook.Worksheets.Item(i).name() = “Sheet1”Then
oSheet = oExcel.ActiveWorkbook.Sheets(WSheet)
Exit For
End If
Next
’通過行列號對單元格進(jìn)行操作
oSheet.Cells(intRow, intColumn).Value
oExcel.Application.DisplayAlerts = False
oExcel.Application.Quit()
oSheet = Nothing
oBook = Nothing
oExcel = Nothing
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請
點(diǎn)擊舉報(bào)。