当前位置:编程学习 > VB >>

大家帮忙看一下这段代码的作用以及哪里有问题


Dim fs, f, ts As Object
Dim arr() As String

Dim arr1() As Sting
Dim arr2() As String

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(E:\down\xls\Availability.properties)
Set ts = f.OpenAsTextStream(FroReading, -1)



Dim intLineCount As Integer
Dim strLine As Integer
intLineCount = 0

Do While ts.AtEndOfStream <> True
strLine = ts.ReadLine
intLineCount = intLineCount + 1
Loop



lines:ActiveWorkbook.ActiveSheet.UsedRange.Columns.Count??count:=sheet.UsedRange.Columns.Count
For i = 1 To intLineCount
    arr(i - 1) = ts.ReadLine
    arr1() = Split(arr(i - 1), "=")
    arr2() = Split(arr1(0))
    
    Dim MyExcel     As New Excel.Application
    MyExcel.Workbooks.Add    
   MyExcel.Visible = True
    
    
    MyExcel.Cells(8 + i - 1, 2) = Trim(arr2(0))
    MyExcel.Cells(8 + i - 1, 7) = Trim(arr2(1))
    MyExcel.Cells(8 + i - 1, 12) = Trim(arr2(2))
    MyExcel.Cells(8 + i - 1, 15) = Trim(arr2(3))
    MyExcel.Cells(8 + i - 1, 19) = Trim(arr2(4))
    
    MyExcel.Cells(8 + i - 1, 24) = arr1(1)
    MyExcel.Cells(8 + i - 1, 38) = arr1(1)
Next i



刚入门,看不懂啊
具体的要求就是读取一个.properties文件,然后将其中的字符分割开,放到excel的不同位置

大家看看应该怎么修改,多谢了
--------------------编程问答-------------------- 新手入门,多多指导 --------------------编程问答-------------------- Dim fs, f, ts As Object
Dim arr() As String

Dim arr1() As Sting
Dim arr2() As String

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(E:\down\xls\Availability.properties)
Set ts = f.OpenAsTextStream(FroReading, -1)



Dim intLineCount As Integer
Dim strLine As Integer
intLineCount = 0

Do While ts.AtEndOfStream <> True
strLine = ts.ReadLine
intLineCount = intLineCount + 1
Loop
redim arr(intlinecount)

For i = 1 To intLineCount
    arr(i - 1) = ts.ReadLine
    arr1() = Split(arr(i - 1), "=")
    arr2() = Split(arr1(0))
    
    Dim MyExcel     As New Excel.Application
    MyExcel.Workbooks.Add    
   MyExcel.Visible = True
    
    
    MyExcel.Cells(8 + i - 1, 2) = Trim(arr2(0))
    MyExcel.Cells(8 + i - 1, 7) = Trim(arr2(1))
    MyExcel.Cells(8 + i - 1, 12) = Trim(arr2(2))
    MyExcel.Cells(8 + i - 1, 15) = Trim(arr2(3))
    MyExcel.Cells(8 + i - 1, 19) = Trim(arr2(4))'能保证有arr2(4)吗?    
    MyExcel.Cells(8 + i - 1, 24) = arr1(1)
    MyExcel.Cells(8 + i - 1, 38) = arr1(1)
Next i --------------------编程问答-------------------- arr2(4)是有的,这样程序写的比较死,但是不会写活了:(
主要是想知道,用这段代码,能否实现读取一个properties文件,并将其内容写到excel的指定位置
补充:VB ,  VBA
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,