赞
踩
- Imports Microsoft.Office.Interop
- 'COM Microsoft Excel x.0 Object Library
-
- Public Class Form1
- Dim exApp As New Excel.Application
- Dim wb As Excel.Workbook
- Dim ws As Excel.Worksheet
-
- Dim openFileDiag As New OpenFileDialog()
- Dim excelPath As String
-
- Dim content(,) As String
-
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- openFileDiag.FileName = ""
- If openFileDiag.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
- excelPath = openFileDiag.FileName
- 'Debug.Print(excelPath)
- End If
- End Sub
-
- Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
- exApp.Visible = False '不显示excel 程序
- wb = exApp.Workbooks.Open(excelPath)
- ws = wb.Sheets(1)
-
- ws.Cells(1, 1).value = "AAA"
- 'Debug.Print(ws.Cells(8, 1).value)
- 'Debug.Print(ws.UsedRange.Rows.Count)
-
- ReDim content(ws.UsedRange.Rows.Count, ws.UsedRange.Columns.Count)
- For i = 1 To ws.UsedRange.Rows.Count
- For j = 1 To ws.UsedRange.Columns.Count
- content(i, j) = ws.Cells(i, j).value
- Debug.Print(content(i, j))
- Next
- Next
-
- wb.Save()
- wb.Close()
- exApp.Quit()
-
- End Sub
- End Class
exsheet:=excelapp.workbooks[1].worksheets[sheetname];
exBook = exApp.Workbooks.Open(appPath)
exSheet = exBook.Sheets.Item(indexSheet)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。