在vb.net中访问Excel文件的用户,可以通过以下步骤进行操作:
完整的示例代码如下:
Imports Microsoft.Office.Interop.Excel
Imports System.Runtime.InteropServices
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim excelApp As New Application()
Dim workbook As Workbook = excelApp.Workbooks.Open("文件路径")
Dim worksheet As Worksheet = workbook.Sheets("工作表名称")
Dim cellValue As String = worksheet.Range("A1").Value
workbook.Close()
excelApp.Quit()
Marshal.ReleaseComObject(worksheet)
Marshal.ReleaseComObject(workbook)
Marshal.ReleaseComObject(excelApp)
End Sub
End Class
注意事项:
Marshal.ReleaseComObject()
方法释放资源。GC.Collect()
和GC.WaitForPendingFinalizers()
进行垃圾回收。推荐的腾讯云相关产品:腾讯云对象存储(COS)
云+社区沙龙online第5期[架构演进]
云+社区沙龙online [新技术实践]
云+社区沙龙online[数据工匠]
企业创新在线学堂
云+未来峰会
云+社区技术沙龙[第11期]
新知·音视频技术公开课
领取专属 10元无门槛券
手把手带您无忧上云