Math 如何在OOo Calc中自动填充OpenOffice数学公式编辑器?
我使用OpenOffice Calc电子表格公式和psuedo随机数生成算术问题数组,我可以轻松更新这些问题以创建新的工作表(我是一名教师) 问题以字符串形式输出为公式标记。OOo数学公式使用这些键入编辑器的字符串命令来显示格式良好的数学表达式 我可以手动执行下一步:Math 如何在OOo Calc中自动填充OpenOffice数学公式编辑器?,math,macros,openoffice.org,openoffice-calc,formula-editor,Math,Macros,Openoffice.org,Openoffice Calc,Formula Editor,我使用OpenOffice Calc电子表格公式和psuedo随机数生成算术问题数组,我可以轻松更新这些问题以创建新的工作表(我是一名教师) 问题以字符串形式输出为公式标记。OOo数学公式使用这些键入编辑器的字符串命令来显示格式良好的数学表达式 我可以手动执行下一步: 1) go to source cell and copy string mark-up to clipboard 2) select target cell and clear existing contents and o
1) go to source cell and copy string mark-up to clipboard
2) select target cell and clear existing contents and objects
3) create new Math object anchored to target cell
4) open Math editor window and paste in mark-up string
5) exit Math editor window and return cursor to source cell
结果:给出了一个很好的数学表达式
我需要能够在不同的工作表上对源单元格的整列执行此操作。
…更好的做法是,添加一个侦听器,以便在源更新时动态更新
我在这里找到了代码:它在一对固定的单元格中实现了这一点,但尽管我尽了最大的努力,我还是不得不承认失败——推广这一代码完全超出了我的专业能力
绝对理想的是一个宏函数,我可以像电子表格函数一样调用它;具有输入参数(sourceCell、targetCell、listenerON/OFF),可以运行上述算法并在需要时动态更新
有人能帮我吗?像这样的解决方案,或者任何一种变通方法都会非常有帮助
更新日期2016/10/27 谢谢Jim K,这确实有效,但是使用dispacher会带来我没有预见到的许多困难。 我刚刚在OpenOffice论坛上找到了它,它使用了API。我已经在下面介绍了我对他的代码的改编 有谁能帮助我以我描述的类似方式将其集成到函数中?我不知道如何解决数学对象在目标单元格中的放置问题 API代码很棒,因为每次更新代码时它都会创建一个新的数学对象。不过,现有的确实需要删除 我认为不能从函数中删除现有对象的限制将继续存在。即使由函数调用的子例程执行,也会出现这种情况吗
function InsertFormula(paraFromCell, paraToCell)
Dim oDoc As Object
Dim oSheet As Object
Dim oShape As Object
oDoc = ThisComponent
oSheet = oDoc.Sheets(0)
oShape = oDoc.createInstance("com.sun.star.drawing.OLE2Shape")
oShape.CLSID = "078B7ABA-54FC-457F-8551-6147e776a997"
oSheet.Drawpage.Add(oShape)
oShape.Model.Formula = paraFromCell
oShape.setSize(oShape.OriginalSize)
end function
下次更新 我已经设法很快地解决了我自己的问题 我决定使用sub,而不是函数,这样我就可以访问工作表来删除现有对象。代码已附加-源单元格位于C列中,目标单元格位于A列的匹配行中。到目前为止,我只能将对象发送到$A$1 如何将每个新对象锚定到特定单元
REM ***** BASIC *****
Sub InsertThisFormula
Dim oDoc As Object
Dim oSheet As Object
Dim oShape As Object
Dim sourceCell As Object
Dim targetCell As Object
oDoc = ThisComponent
oSheet = oDoc.Sheets(1)
Dim n As Integer
n = 1 'number of rows of formulas
for i = 0 To n-1
rem loop through cells
sourceCell = oSheet.getCellByPosition(2, i)
targetCell = oSheet.getCellByPosition(0, i)
rem clear target cell object/s
targetCell.ClearContents(128)
oShape = oDoc.createInstance("com.sun.star.drawing.OLE2Shape")
oShape.CLSID = "078B7ABA-54FC-457F-8551-6147e776a997"
oSheet.Drawpage.Add(oShape)
oShape.Model.Formula = sourceCell.string
oShape.setSize(oShape.OriginalSize)
Next i
End Sub
从Mifeet的示例开始,将其添加到我的宏中:
rem----------------------------------------------------------------------
rem根据文本创建数学公式
函数InsertFormulaFromCell(paramCellFrom,paramCellTo)
将文档变暗为对象
dim dispatcher作为对象
文档=ThisComponent.CurrentController.Frame
dispatcher=createUnoService(“com.sun.star.frame.DispatchHelper”)
rem转到包含标记的单元格并复制它
从Cellargs(0)变暗为新的com.sun.star.beans.PropertyValue
fromcellgs(0)。Name=“ToPoint”
FromCellGS(0)。值=paramCellFrom
dispatcher.executeDispatch(文档“.uno:GoToCell”,”,0,fromcellgs())
dispatcher.executeDispatch(文档“.uno:Copy”,”,0,数组())
rem转到要显示公式的单元格
将toCellArgs(0)暗显为新的com.sun.star.beans.PropertyValue
toCellArgs(0)。Name=“ToPoint”
toCellArgs(0).Value=paramCellTo
dispatcher.executeDispatch(文档“.uno:GoToCell”,”,0,toCellArgs())
rem开放之星。数学
oDesk=createUnoService(“com.sun.star.frame.Desktop”)
dispatcher.executeDispatch(文档“.uno:InsertObjectStarMath”,”,0,Array())
文档=ThisComponent.CurrentController.Frame
dispatcher=createUnoService(“com.sun.star.frame.DispatchHelper”)
rem使用数组()作为变量名的占位符粘贴剪贴板
dispatcher.executeDispatch(文档“.uno:Paste”,”,0,数组())
rem退出星。数学
dispatcher.executeDispatch(_
文档“.uno:TerminateInplaceActivation”,”,0,数组()
InsertFormulaFromCell=“数学公式已更新”&Now()
端函数
要运行它,请将此公式放入单元格C5:
=INSERTFORMULAFROMCELL("$C$3","$C$20")
现在,当值更新时,它会创建另一个公式
注意:我无法使Mifeet代码的
.uno:Delete
部分正常工作,可能是因为函数不应该访问其他单元格。这可能需要在创建新公式之前手动删除公式。从Mifeet的示例开始,将其添加到我的宏中:
rem----------------------------------------------------------------------
rem根据文本创建数学公式
函数InsertFormulaFromCell(paramCellFrom,paramCellTo)
将文档变暗为对象
dim dispatcher作为对象
文档=ThisComponent.CurrentController.Frame
dispatcher=createUnoService(“com.sun.star.frame.DispatchHelper”)
rem转到包含标记的单元格并复制它
从Cellargs(0)变暗为新的com.sun.star.beans.PropertyValue
fromcellgs(0)。Name=“ToPoint”
FromCellGS(0)。值=paramCellFrom
dispatcher.executeDispatch(文档“.uno:GoToCell”,”,0,fromcellgs())
dispatcher.executeDispatch(文档“.uno:Copy”,”,0,数组())
rem转到要显示公式的单元格
将toCellArgs(0)暗显为新的com.sun.star.beans.PropertyValue
toCellArgs(0)。Name=“ToPoint”
toCellArgs(0).Value=paramCellTo
dispatcher.executeDispatch(文档“.uno:GoToCell”,”,0,toCellArgs())
rem开放之星。数学
oDesk=createUnoService(“com.sun.star.frame.Desktop”)
dispatcher.executeDispatch(文档“.uno:InsertObjectStarMath”,”,0,Array())
文档=ThisComponent.CurrentController.Frame
dispatcher=createUnoService(“com.sun.star.frame.DispatchHelper”)
rem使用数组()作为变量名的占位符粘贴剪贴板
dispatcher.executeDispatch(文档“.uno:Paste”,”,0,数组())
rem退出星。数学
dispatcher.executeDispatch(_
医生
REM ***** BASIC *****
Sub InsertThisFormula
Dim oDoc As Object
Dim oSheet As Object
Dim oShape As Object
Dim sourceCell As Object
Dim targetCell As Object
oDoc = ThisComponent
oSheet = oDoc.Sheets(1)
Dim n As Integer
n = 6 'number of rows of formulas
for i = 0 To n-1
rem loop through cells
sourceCell = oSheet.getCellByPosition(2, i)
targetCell = oSheet.getCellByPosition(3, i)
rem clear target cell object/s
targetCell.ClearContents(128)
oShape = oDoc.createInstance("com.sun.star.drawing.OLE2Shape")
oShape.CLSID = "078B7ABA-54FC-457F-8551-6147e776a997"
oSheet.Drawpage.Add(oShape)
oShape.Model.Formula = sourceCell.string
oShape.setSize(oShape.OriginalSize)
oShape.Anchor = targetCell
oShape.MoveProtect = True
Next i
End Sub