您的位置:首页 > 运维架构

Excel和OpenFileDialog

2012-04-26 23:01 274 查看
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


excelapp.workbooks.add(filename);

exsheet:=excelapp.workbooks[1].worksheets[sheetname];

exBook = exApp.Workbooks.Open(appPath)

exSheet = exBook.Sheets.Item(indexSheet)


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: