我希望能够交换2个区域(这些区域可以是相邻的列,但可以是任何大小的矩形)。
到目前为止,我已经达到以下目标: How can you extract the currently-selected range of cells in LibreOffice calc via pyuno?和 https://forum.openoffice.org/en/forum/viewtopic.php?f=45&t=19528
有人已经为此使用了有用的宏,还是可以帮助我完成我的工作? 或者,如果有人对用户界面有更好的想法,也请
。注意:这比How to swap two cells in LibreOffice Calc
更笼统sub Area_swapping
desktop = XSCRIPTCONTEXT.getDesktop()
model = desktop.getCurrentComponent()
try:
sheets = model.getSheets()
except AttributeError:
raise Exception("This script is for Calc Spreadsheets only")
#sheet = sheets.getByName('Sheet1')
# identify source content
sheet = model.CurrentController.getActiveSheet()
oSelection_source = model.getCurrentSelection()
oArea_source = oSelection_source.getRangeAddress()
first_row_source = oArea_source.StartRow
last_row_source = oArea_source.EndRow
first_col_source = oArea_source.StartColumn
last_col_source = oArea_source.EndColumn
width_source = last_row_source - ( first_row_source - 1 )
height_source = last_col_source - ( first_col_source - 1 )
# reserve source content (ie oTemp = oArea_source )
?? what is the object to keep?
# wait for selection of target area
??
# compare dimensions and swap
if ((width_source = width_target) and (height_source = height_target)) then
oArea_source = oArea_target
oArea_target = oTemp
elseIf ((width_source = height_target) and (height_source = width_target)) then
# or check to swap transposed
iAnswer = Msgbox("Yes or No?", 3 +32 +256, "Do you want to copy transposed?")
# 3 shows Yes, No and Cancel buttons, 32 a ?-icon, 256 focuses "No"
#REM execution continues if one of the 3 buttons have been pushed
If iAnswer = 6 then ' return value of "Yes"
# transpose?? and copy
elseIf iAnswer = 7 then ' return value of "No"
MsgBox "Source and Target dimensions do not match.\n Nothing was done."
endif
else
raise Exception("Source and Target dimensions do not match!")
end if
End Sub