16,554
社区成员
发帖
与我相关
我的任务
分享
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim xlApp As Microsoft.Office.Interop.Excel.Application
Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
Dim this As Boolean = True
xlApp = New Microsoft.Office.Interop.Excel.Application
If Not FileIO.FileSystem.FileExists("E:\001.xls") Then
MsgBox("文件不存在!")
Return
End If
xlBook = xlApp.Workbooks.Open("E:\001.xls")
xlSheet = xlBook.Worksheets(1) '用第一个sheet
xlApp.ActiveWindow.DisplayGridlines = False
Dim i As Integer = 0
Dim j As Integer = 0
Dim strA As String = "ABCDEFGHIJKLMN"
Dim str As String = ""
With xlSheet
For i = 1 To 10
For j = 1 To 10
str = .Range(strA.Chars(i - 1) & String.Concat(j)).Value
If str <> Nothing Then
ListBox1.Items.Add(str)
End If
Next
Next
End With
xlBook.Save()
xlBook.Close()
xlApp.Quit()
xlApp.Quit()
xlApp.Quit()
xlApp.Quit()
xlApp.Quit()
End Sub
Dim xlApp As Microsoft.Office.Interop.Excel.Application
Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
Dim this As Boolean = True
xlApp = New Microsoft.Office.Interop.Excel.Application
If Not FileIO.FileSystem.FileExists("E:\001.xls") Then
MsgBox("文件不存在!")
Return
End If
xlBook = xlApp.Workbooks.Open("E:\001.xls")
xlSheet = xlBook.Worksheets(1) '用第一个sheet
xlApp.ActiveWindow.DisplayGridlines = False
Dim i As Integer = 0
Dim j As Integer = 0
Dim strA As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Dim str As String = ""
str = TextBox1.Text.ToUpper
i = str.IndexOf(":")
Dim strF As String = ""
Dim strB As String = ""
strF = str.Substring(0, i)
strB = str.Substring(i + 1, str.Length - i - 1)
For i = 0 To strF.Length - 1
If Char.IsNumber(strF.Chars(i)) Then Exit For
Next
Dim strFA As String = strF.Substring(0, i)
Dim strFi As Integer = Integer.Parse(strF.Substring(i, strF.Length - 1))
For i = 0 To strB.Length - 1
If Char.IsNumber(strB.Chars(i)) Then Exit For
Next
Dim strBA As String = strB.Substring(0, i)
Dim strBi As Integer = Integer.Parse(strB.Substring(i, strB.Length - 1))
Dim ddd As String
Dim dx As String
With xlSheet
For j = strFi To strBi
ddd = ""
For i = Integer.Parse(strA.IndexOf(strFA)) + 1 To Integer.Parse(strA.IndexOf(strBA)) + 1
str = .Range(strA.Chars(i - 1) & String.Concat(j)).Value
Dim ch As Char = " "
If str = Nothing Then
dx = New String(ch, 20) '相当于设置每列数据的宽度=20
Else
dx = New String(ch, (20 - str.Length - 1)) '相当于设置每列数据的宽度=20
End If
str = str & dx
ddd = ddd & str
Next
ListBox1.Items.Add(ddd)
Next
End With
xlBook.Save()
xlBook.Close()
xlApp.Quit()
For i = 1 To 10
For j = 1 To 10
str = .Range(strA.Chars(i - 1) & String.Concat(j)).Value
If str <> Nothing Then
ListBox1.Items.Add(str)
End If
Next
Next
For i = 2 To 19
For j = 2 To 18
str = .Range(strA.Chars(i - 1) & String.Concat(j)).Value
If str <> Nothing Then
ListBox1.Items.Add(str)
End If
Next
Next