gpt4 book ai didi

openoffice-calc - 公式内的单元格内容

转载 作者:行者123 更新时间:2023-12-04 08:45:15 28 4
gpt4 key购买 nike

是否可以将单元格的内容放在公式中。我所说的公式是指数学公式编辑器(插入-> 对象-> 公式)。

最佳答案

据我所知,无法从公式中引用单元格。数学公式编辑器对 OO Calc 一无所知。但是,您可以在需要时使用宏创建新公式。

请按照以下步骤使其工作:

  • 将要插入的数学公式放入单元格。例如,将一些数字放入单元格 A1、A2、A3 并将以下内容放入单元格 C3:
    =CONCATENATE("{";A1;"}";"over {";A2;" `+` ";A3;"}";" `=` ";A4).

    这将生成类似 {1} over {2 `+` 3} `= 的内容在 C3
  • 从下面的代码创建一个宏。在 OO Calc 中,选择
    Tools > Macros > Organize Macros > OpenOffice.org Basic > My Macros > Standard

    创建一个新的宏并粘贴下面的代码。
  • 现在您可以使用 Tools > Macros > Run Macro 运行宏.运行 insertFormula插入从单元格 C3 生成的数学公式,或 addFormulaListener当 C3 的内容发生变化时,它将注册一个监听器并为您重新生成公式。

  • 这是代码。它包含常量 formulaCellFromformulaCellTo ,指定哪个单元格具有数学公式源,哪个是生成的公式对象应放置的目标单元格。注意目标单元格对于生成的公式必须足够大,否则宏在重新生成公式时不会删除单元格的旧内容。
    const formulaCellFrom As String = "$C$1"
    const formulaCellTo As String = "$C$10"

    rem ----------------------------------------------------------------------
    rem Adds listener for changes of the math formula
    sub addFormulaListener
    dim oSheet as Object
    dim oCell as Object
    rem go to cell containing markup
    oSheet = ThisComponent.CurrentController.ActiveSheet
    oCell = oSheet.getCellRangeByName(formulaCellFrom)
    rem add listener
    oListener = CreateUnoListener( "formulaListener_", "com.sun.star.chart.XChartDataChangeEventListener" )
    oCell.addChartDataChangeEventListener(oListener)
    end sub

    rem ----------------------------------------------------------------------
    rem Listener for cell changes
    sub formulaListener_chartDataChanged
    dim oCell as Object

    rem remember current cursor position
    oCell = ThisComponent.CurrentSelection

    rem call insertFormula
    call insertFormula

    rem restore cursor position
    ThisComponent.CurrentController.select(oCell)
    end sub

    rem ----------------------------------------------------------------------
    rem Creates a math formula from text in cell C1 and inserts it into cell C10
    sub insertFormula

    dim document as object
    dim dispatcher as object
    rem get access to the document
    document = ThisComponent.CurrentController.Frame
    dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

    rem go to cell containing markup and copy it
    dim fromCellArgs(0) as new com.sun.star.beans.PropertyValue
    fromCellArgs(0).Name = "ToPoint"
    fromCellArgs(0).Value = formulaCellFrom
    dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, fromCellArgs())
    dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())

    rem go to cell where I want the formula displayed
    dim toCellArgs(0) as new com.sun.star.beans.PropertyValue
    toCellArgs(0).Name = "ToPoint"
    toCellArgs(0).Value = formulaCellTo
    dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, toCellArgs())

    rem delete previous content
    dim deleteArgs(0) as new com.sun.star.beans.PropertyValue
    deleteArgs(0).Name = "Flags"
    rem flags: A = All, S = String, V = Value, D = DateTeim, F = Formula, ...
    rem ... N = Notes, T = Formats, O = Objects
    deleteArgs(0).Value = "AO"
    dispatcher.executeDispatch(document, ".uno:Delete", "", 0, deleteArgs())

    rem open Star.Math
    oDesk = createUnoService ("com.sun.star.frame.Desktop")
    dispatcher.executeDispatch(document, ".uno:InsertObjectStarMath", "", 0, Array())

    rem get access to the document
    document = ThisComponent.CurrentController.Frame
    dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

    rem paste clipboard using Array() as place-holder for variable name
    dispatcher.executeDispatch(document, ".uno:Paste", "", 0, Array())

    rem exit Star.Math
    dispatcher.executeDispatch(document, ".uno:TerminateInplaceActivation", "", 0, Array())
    end sub

    代码改编自 this question .显然,宏必须在 My Macros 中创建并且在嵌入电子表格时不起作用(安全措施?它对我不起作用)。源和目标单元格是硬编码的,但您可以修改宏以满足您的需要。我不擅长 Visual Basic,但这种修改应该很容易。

    关于openoffice-calc - 公式内的单元格内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15369279/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com