2014-09-05 84 views
0

所以我正在研究一个基本的宏,现在我需要比较两列的重复项。OpenOffice比较两个单元格字符串

这里是我迄今打算:

for i = 0 To 5 
    Cell1 = Sheet.getCellByPosition(0,i) 

    for j = 0 to 5 
    Cell2 = Sheet.getCellByPosition(1,j) 

    rem COMPARISON WOULD HAPPEN HERE 

    Next j 
Next i 

我愿做线沿线的东西:如果Cell1.String == Cell2.String然后...

这是我的首先尝试编写一个宏,所以我非常感谢任何帮助和/或指导。

谢谢!

同样在一个侧面说明,如果有人知道好tutorials.documentation比维基这个其他的,我将非常感谢您的链接

回答

0

你应该第一列的所有值存储到一个数组,然后比较第二列的每个值都与数组中的所有条目一起使用简单的递归。

可工作的代码是

Dim firstcolumn(5) As String 

For i = 0 to 5 
    firstcolumn(i) = Sheet.getCellByPosition(0,i) 
Next i 

For j = 0 to 5 
    Cell2 = Sheet.getCellByPosition(1,j) 
    for i = 0 to 5 
    if Cell2 = firstcolumn(i) then 
     MsgBox("The value of the cell " + i + " in the first column is the same with the value of the cell " + j + " of the second column") 
    Next i 
Next j 

寻找代码样本的最佳位置是OpenOffice的论坛https://forum.openoffice.org/en/forum/

我希望上面会帮你的。