【问题标题】:Libreoffice calc: loop throught cells macroLibreoffice calc:循环遍历单元格宏
【发布时间】:2013-10-25 04:03:33
【问题描述】:

我搜索了很多,但几乎找不到关于 LibreOffice Basic 的信息

我有点习惯在 excel 中编写宏,但这次需要循环,直到我到达第一个空列并且它需要在 libreoffice 中。

在excel中我会做这样的事情:

Dim i As integer

i = 0
Range("A1").Select
While cell.Offset(0, i).Value <> Null
    i = i + 1
Wend
MsgBox ("First empty column is " & Chr(i + 64))

但在 libreoffice 我不知道。

谁能帮帮我。

谢谢, 布鲁诺

【问题讨论】:

    标签: macros libreoffice libreoffice-basic libreoffice-calc


    【解决方案1】:

    我设法通过这种方式找到了答案:

    dim cell as object
    dim i as integer
    
    i = 0
    cell = Sheet.getCellByPosition(i,0)
    
    while Cell.Type <> com.sun.star.table.CellContentType.EMPTY
        i = i+1
        cell = Sheet.getCellByPosition(i,0)
    wend
    

    当循环结束时,我得到变量i,它对应于列号。然后我可以像在 excel 中一样将它转换为字母(chr 函数)

    【讨论】:

      【解决方案2】:
      rem I had a similar problem to solve.
      rem Update for libreoffice 7.
      rem Replaced "sheet" with "ThisComponent.Sheets(0)". 
      rem Thanks.
      
      
      sub main 
      dim cell   as object
      dim i      as integer
      
      i = 0
      rem "sheet" alone does not run
      cell = ThisComponent.Sheets(0).getCellByPosition(i,0) 
      
      while Cell.Type <> com.sun.star.table.CellContentType.EMPTY
          i    = i+1
          cell = ThisComponent.Sheets(0).getCellByPosition(i,0)   
      wend
      MsgBox( i )
      end sub 
      

      【讨论】:

      • 虽然这段代码可以解决问题,但including an explanation 确实有助于提高帖子的质量。请记住,您是在为将来的读者回答问题,而这些人可能不知道您提出代码建议的原因
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-15
      • 2021-06-28
      • 1970-01-01
      相关资源
      最近更新 更多