将数据从一个CSV文件解析到另一个CSV文件

时间:2013-05-28 20:29:44

标签: csv macros openoffice.org openoffice-basic

我正在尝试运行此宏,但由于我的CSV文件很长并且我不想计算列数,有没有办法通过诸如“DZ”之类的字母来引用列?代码工作正常但我只需要引用这些深列,并且不想计算它是哪个列号,并且似乎无法找到显示列号的方法。我一直在设置'c'和amp; 't'作为列号,例如1,2等

Sub ParseColumn

Dim sheet1 as Object
Dim sheet2 as Object
Dim r as long
Dim c as long

sheet1 = ThisComponent.Sheets.getbyname("Sheet1")
sheet2 = ThisComponent.Sheets.getbyname("Sheet2")

c = F
t = DZ

for r = 1 to 18739

    copyFrom = sheet1.getCellByPosition(c,r)

    copyTo = sheet2.getCellByPosition(t,r)

    copyTo.String = copyFrom.String 

next r

End Sub

更新 找到了解决方案:

Sub ParseColumn

Dim sheet1 as Object
Dim sheet2 as Object
Dim r as long

sheet1 = ThisComponent.Sheets.getbyname("Sheet1")
sheet2 = ThisComponent.Sheets.getbyname("Sheet2")

for r = 2 to 18739

    copyFrom = sheet1.getCellRangeByName("AR" & r)

    copyTo = sheet2.getCellRangeByName("S" & r)

    copyTo.String = copyFrom.String 

next r

End Sub

0 个答案:

没有答案