我想从单元格范围(L3:L10)到单元格范围(H10:H11)仅复制格式(无值)。
使用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
但是使用LibreOffice?
你能帮助我吗?
答案 0 :(得分:0)
我运行了宏录制器,它生成了这个:
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
虽然代码很丑陋,但仍然适用于调度程序代码。您要求的范围是不同的大小,因此它会生成警告。只需使用" $ L $ 3:$ L $ 4"就可以很容易地解决这个问题。作为源范围。
API代码会更短更清晰。有关使用XTransferableSupplier的示例,请参阅openoffice: duplicating rows of a table in writer。但是,可能无法仅使用XTransferable粘贴格式。