求vb.net 操作Excel2003的代码?
求vb.net 操作Excel2003的代码?
[解决办法]
首先要在引用里添回excel的引用。
不知道你具体要操作什么,以下是我的一部分代码,是打开了一个excel文件。你可以针对你的问题,在百度搜一下。有很多的资料
Dim xlApp As Excel.ApplicationClass = New Excel.ApplicationClass
Dim xlWorkbook As Excel.Workbook
oMissing = System.Reflection.Missing.Value
xlWorkbook = xlApp.Workbooks.Open(filePath, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing)
' 得到Excel中sheet的名称()
Dim Mysheets As Excel.Sheets = xlWorkbook.Sheets
Dim xlWorksheet As Excel._Worksheet = Mysheets.Item(1)
'Dim xlWorksheet As Excel._Workbook = (Excel._Worksheet)Mysheets.get_Item(1)
Dim filename As String = xlWorksheet.Name
xlApp.Workbooks.Close()