vb.net 操作excel
2020-02-16 09:40
204 查看
Imports Microsoft.Office.Interop.Excel
Public Class Form1
Dim data_arr() As String
Sub excelConnection() Dim newsht As Worksheet Dim excelpath As String Dim shtname As String Dim wkbook As Workbook Dim excelapp As Application Dim teststr As String Dim totalcells As Integer excelapp = CreateObject("Excel.Application") shtname = "testsht.xlsx" excelpath = "D:\Backup\桌面\intentory_end_of_2016\" wkbook = excelapp.Workbooks.Open(excelpath & shtname) excelapp.Visible = False newsht = wkbook.Sheets(1) teststr = newsht.Range("A1").Text totalcells = getlastcell(newsht) 'fill the array ReDim data_arr(totalcells) Dim i_this As Integer For i_this = 1 To UBound(data_arr) data_arr(i_this - 1) = newsht.Range("A" & i_this + 1).Text Next Me.Label1.Text = totalcells Me.Label2.Text = teststr 'Debug.Print(totalcells) 'MsgBox(teststr) 'MsgBox(newsht.Name) 'lease the control of excel wkbook.Close() excelapp = Nothing wkbook = Nothing newsht = Nothing End Sub 'get the max number of one column that is not empty Public Function getlastcell(sht As Worksheet) As Int16 Dim i As Int16 i = 1 Do While (sht.Range("A" & i).Text <> "") i = i + 1 Loop getlastcell = i - 1 End Function Private Sub FolderBrowserDialog1_HelpRequest(sender As Object, e As EventArgs) Handles FolderBrowserDialog1.HelpRequest End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Call excelConnection() End Sub Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged Dim str As String Me.ListBox1.Items.Clear() If UBound(data_arr) > 0 And Me.TextBox1.Text <> "" Then For Each str In data_arr If str Like "*" + UCase(Me.TextBox1.Text) + "*" Then Me.ListBox1.Items.Add(str) End If Next End If End Sub Private Sub ListBox1_DoubleClick(sender As Object, e As EventArgs) Handles ListBox1.DoubleClick Dim pdfpath As String Dim selectedPartcode As String pdfpath = "D:\Backup\桌面\intentory_end_of_2016\drawings_pdf\" selectedPartcode = Me.ListBox1.SelectedItem.ToString 'MsgBox(pdfpath + selectedPartcode) System.Diagnostics.Process.Start(pdfpath + selectedPartcode) End Sub
End Class
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- [转]利用adsutil.vbs脚本创建自定义web站点
- 免费万能视频格式转换器是一款功能强大的全能视频格式转换软件,支持多种视频格式转换。万能视频转换器可以将RM、RMVB
- VBA隐藏Word表格行
- Microsoft Project的RibbonXml VBA项目中不能使用带参数的过程
- Office 2010下VBA Addressof的应用
- Outlook 2010中添加自定义Form并使用VB代码处理事务的示例
- win7升级win10后,以前用来操作WORD的VB程序无法正常加载MSWORD文件,具体处理方法
- VB语音开发
- VBA中关于WORD的基本应用 比如批量改页眉页脚,从文件名取数字作为页眉等等。
- 想要学习vb 2008 ,有资源么??同志们
- 学习vb的过程
- 开始学习VB.ENT
- vb 错误捕捉 代码
- 在VB中如何使用ping命令
- VB micsendstring 的属性及用法
- VB 截取picturebox里面全部
- VB中延时功能与Sleep函数
- VB动态生成与删除控件
- vb动态创建控件
- 动态创建和删除VB控件