如何使用 libreoffice 宏将文本放入当前选定单元格左侧的单元格中?

How do I put text into the cell to the left of the currently selected cell with a libreoffice macro?

我正在尝试编写一个宏,它从当前选定的单元格中获取一个字符串,并将该字符串的修改版本放入选定单元格左侧的单元格中。

到目前为止,我的 Google-fu 已经让我获得了所选单元格的内容并操作了字符串,因此它已准备好进入左侧第一个单元格,如下所示:

oCell = ThisComponent.getCurrentSelection()
dim d1 as string
dim d2 as string
dim d3 as string
dim d4 as string
dim d5 as string

d1=oCell.getString()
d2=mid(d1,1,2)
d3=mid(d1,4,2)
d4=mid(d1,7,4)
d5=d4+d3+d2

但我不知道如何将 d5 放入 oCell

左侧的单元格中

我什至还没有开始研究如何让它对一系列选定的单元格起作用,我想我会先让它对一个单元格起作用:)

Andrew Pitonyak 撰写的 OpenOffice 宏解释 一书是 OpenOffice API 的一个很好的资源,可从 his website 免费下载。

另一个资源是 Xray 工具,可从 Bernard Marcelly's website 获得。下面是 Xray 工具检查 oCell 对象的图片,显示它有一个方法 .getCellAddress,returns 一个具有属性 ColumnRow 和 [=14= 的结构].

知道这一点,您可以看到类似这样的代码会让您将单元格移至左侧(当然,您需要添加错误检查以确保您不在最左侧的列中):

oAddress = oCell.getCellAddress()
oLeftCell = ThisComponent.Sheets(oAddress.Sheet).getCellByPosition(oAddress.Column-1,oAddress.Row)
oLeftCell.setString(d5)