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()