简体   繁体   English

仅复制单元格格式(无值)

[英]copy only cell format (no value)

I'd like copy only format (no value) from cell range (L3:L10) to cell range (H10:H11). 我想要从单元格范围(L3:L10)到单元格范围(H10:H11)的仅复制格式(无值)。

With Excel is easy: 使用Excel很容易:

Sheets(sheet1).Range("L3:L10").Select 
Selection.Copy 
Sheets(sheet1).Range("H10:H11").Select 
Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=False 

But with LibreOffice? 但是使用LibreOffice?

Can you help me? 你能帮助我吗?

I ran the macro recorder, and it generated this: 我运行了宏记录器,它生成了以下代码:

Sub PasteFormatting
    dim document   as object
    dim dispatcher as object
    document = ThisComponent.CurrentController.Frame
    dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

    dim args1(0) as new com.sun.star.beans.PropertyValue
    args1(0).Name = "ToPoint"
    args1(0).Value = "$L$3:$L$10"
    dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1())
    dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())

    dim args3(0) as new com.sun.star.beans.PropertyValue
    args3(0).Name = "ToPoint"
    args3(0).Value = "$H$10:$H$11"
    dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args3())

    dim args4(5) as new com.sun.star.beans.PropertyValue
    args4(0).Name = "Flags"
    args4(0).Value = "T"
    args4(1).Name = "FormulaCommand"
    args4(1).Value = 0
    args4(2).Name = "SkipEmptyCells"
    args4(2).Value = false
    args4(3).Name = "Transpose"
    args4(3).Value = false
    args4(4).Name = "AsLink"
    args4(4).Value = false
    args4(5).Name = "MoveMode"
    args4(5).Value = 6
    dispatcher.executeDispatch(document, ".uno:InsertContents", "", 0, args4())
End Sub

It works, although the code is ugly, as is to be expected of dispatcher code. 它可以工作,尽管代码很丑陋,正如调度程序代码所期望的那样。 The ranges you asked for are different sizes, so it generates a warning. 您要求的范围是不同的大小,因此会生成警告。 It would be easy to fix this by simply using "$L$3:$L$4" as the source range. 只需使用“ $ L $ 3:$ L $ 4”作为源范围,即可轻松解决此问题。

API code would be much shorter and cleaner. API代码将更短,更简洁。 For an example using XTransferableSupplier , see openoffice: duplicating rows of a table in writer . 有关使用XTransferableSupplier的示例,请参见openoffice:在writer中复制表的行 However, it may not be possible to paste only formatting with XTransferable. 但是,可能无法仅使用XTransferable粘贴格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM