当前位置:   article > 正文

Excel和OpenFileDialog_openfiledialog限制excle

openfiledialog限制excle
  1. Imports Microsoft.Office.Interop
  2. 'COM Microsoft Excel x.0 Object Library
  3. Public Class Form1
  4. Dim exApp As New Excel.Application
  5. Dim wb As Excel.Workbook
  6. Dim ws As Excel.Worksheet
  7. Dim openFileDiag As New OpenFileDialog()
  8. Dim excelPath As String
  9. Dim content(,) As String
  10. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  11. openFileDiag.FileName = ""
  12. If openFileDiag.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
  13. excelPath = openFileDiag.FileName
  14. 'Debug.Print(excelPath)
  15. End If
  16. End Sub
  17. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  18. exApp.Visible = False '不显示excel 程序
  19. wb = exApp.Workbooks.Open(excelPath)
  20. ws = wb.Sheets(1)
  21. ws.Cells(1, 1).value = "AAA"
  22. 'Debug.Print(ws.Cells(8, 1).value)
  23. 'Debug.Print(ws.UsedRange.Rows.Count)
  24. ReDim content(ws.UsedRange.Rows.Count, ws.UsedRange.Columns.Count)
  25. For i = 1 To ws.UsedRange.Rows.Count
  26. For j = 1 To ws.UsedRange.Columns.Count
  27. content(i, j) = ws.Cells(i, j).value
  28. Debug.Print(content(i, j))
  29. Next
  30. Next
  31. wb.Save()
  32. wb.Close()
  33. exApp.Quit()
  34. End Sub
  35. End Class

excelapp.workbooks.add(filename); 

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


exBook = exApp.Workbooks.Open(appPath)

        exSheet = exBook.Sheets.Item(indexSheet)


                
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/698893
推荐阅读
相关标签
  

闽ICP备14008679号