LibreOffice Calc 宏可将一张工作表中的范围复制到另一张工作表中的不同位置

问题描述 投票:0回答:1

使用宏,我想将 Sheet1,B2:D5 中的任何内容复制到 Sheet2,A1 作为“标题单元格”。网络上有很多关于此的“边缘调情”页面,但我无法发现任何具体内容,而且我无法调整他们的代码我想要做的事情,这非常令人失望,正如我所希望的那样现在能够在 LO basic 中“自行生成”代码,但显然不能:( 有人可以发布一个简单的宏来说明如何做到这一点吗?

编辑:这就是我所在的地方...

Sub try6

    Dim oSourceSheet as Object
    Dim oTargetSheet as Object
    Dim SourceRange As New com.sun.star.table.CellRangeAddress ' SourceRange with later Sheet1 like properties of what to copy '
    Dim TargetRange As New com.sun.star.table.CellAddress  ' TargetRange with later Sheet2 like properties of what to copy '

    oSourceSheet = ThisComponent.Sheets.getByName("Sheet1")
    oTargetSheet = ThisComponent.Sheets.getByName("Sheet2")   
    oSourceRange = oSourceSheet.getCellRangeByName("B2:D3") ' Specify the range to copy
    oTargetRange = oTargetSheet.getCellRangeByName("A1") ' Specify the header cell for pasting

    oTargetSheet.copyRange(TargetRange, SourceRange) ' Now nothing at all happens when the macro triggering button is pressed
    
End Sub

附注我可以使用循环来做到这一点,但作为“粘贴块范围”是我失败的地方,但这就是我想要的方式。

macros libreoffice calc
1个回答
0
投票

您可以在 LibreOffice 中录制宏,但它是有限的

使用此功能,创建了 LibreOffice,在格式上进行了一些小的更改:

REM  *****  BASIC  *****

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

    rem ----------------------------------------------------------------------
    dim args2(0) as new com.sun.star.beans.PropertyValue
    args2(0).Name = "ToPoint"
    args2(0).Value = "$B$2:$D$5"

    dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args2())

    rem ----------------------------------------------------------------------
    dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())

    rem ----------------------------------------------------------------------
    dim args4(0) as new com.sun.star.beans.PropertyValue
    args4(0).Name = "Nr"
    args4(0).Value = 2

    dispatcher.executeDispatch(document, ".uno:JumpToTable", "", 0, args4())

    rem ----------------------------------------------------------------------
    dim args5(5) as new com.sun.star.beans.PropertyValue
    args5(0).Name = "Flags"
    args5(0).Value = "SVD"
    args5(1).Name = "FormulaCommand"
    args5(1).Value = 0
    args5(2).Name = "SkipEmptyCells"
    args5(2).Value = false
    args5(3).Name = "Transpose"
    args5(3).Value = false
    args5(4).Name = "AsLink"
    args5(4).Value = false
    args5(5).Name = "MoveMode"
    args5(5).Value = 4

    dispatcher.executeDispatch(document, ".uno:InsertContents", "", 0, args5())

end sub
© www.soinside.com 2019 - 2024. All rights reserved.