OpenOffice calc,宏可以自动更新单元格内容吗?

问题描述

我使用了在网上论坛上找到的一个宏。

它检测指定单元格的背景颜色并返回该背景颜色的数值。问题是它只做一次。当我更改指示单元格的背景颜色时,数值不会更新。 要更新它,我必须在我调用宏的单元格中更改某些内容(例如,删除一个字符并重新键入它),然后按 Enter。然后更新数值。

有没有办法让它自动更新?或者,是否有一种更简单的方法来更新它(与所描述的删除和重新键入方法相比),最好是一种同时适用于多个单元格的方法

Villeroy 在 openoffice 论坛上的代码

Function CELL_BACKCOLOR(vSheet,lRowIndex&,iColIndex%)
'calls: getSheetCell
REM returns color code as number
Dim v
   v = getSheetCell(vSheet,iColIndex%)
   if vartype(v) = 9 then
      CELL_BACKCOLOR = v.CellBackColor
   else
      CELL_BACKCOLOR = v
   endif
End Function

Function getSheetCell(byVal vSheet,byVal lRowIndex&,byVal iColIndex%)
dim oSheet
'   print vartype(vsheet)
   oSheet = getSheet(vSheet)
   if varType(oSheet) <>9 then
      getSheetCell = NULL
   elseif (lRowIndex > oSheet.rows.count)OR(lRowIndex < 1) then
      getSheetCell = NULL
   elseif (iColIndex > oSheet.columns.count)OR(iColIndex < 1) then
      getSheetCell = NULL
   else
      getSheetCell = oSheet.getCellByPosition(iColIndex -1,lRowIndex -1)
   endif
End Function

解决方法

我不知道为什么“自动计算”设置在这种情况下不起作用(用 LibreOffice 7.0.2 测试)。无论如何,您可以手动更新单个单元格或多个单元格的宏输出:

  • 对于单个单元格,点击 F9
  • 对于多个单元格,选择它们并按 CTRL + SHIFT + F9