欢迎使用CSDN-markdown编辑器

来源:互联网 发布:福建11选5遗漏数据查询 编辑:程序博客网 时间:2024/06/05 03:25

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 = NothingEnd Sub'get the max number of one column that is not emptyPublic 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 - 1End FunctionPrivate Sub FolderBrowserDialog1_HelpRequest(sender As Object, e As EventArgs) Handles FolderBrowserDialog1.HelpRequestEnd SubPrivate Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click    Call excelConnection()End SubPrivate 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 IfEnd SubPrivate 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

0 0