Here is what I wrote a few years ago to move column "C" to the location of "A",
as Niklas suggests. :-)
Sub Main
oSheet = ThisComponent.getCurrentController().getActiveSheet()
Move_Column(oSheet, "C", "A")
End Sub
Sub Move_Column(oSheet, sFrom, sTo)
cFrom = oSheet.getColumns().getByName(sFrom)
cTo = oSheet.getColumns().getByName(sTo)
oSheet.getColumns.insertByIndex(cTo.getRangeAddress().StartColumn, 1)
iToBeRemoved = cFrom.getRangeAddress().StartColumn
cTo = oSheet.getColumns().getByName(sTo)
oSheet.moveRange(cTo.getCellByPosition(0, 0).getCellAddress(),
cFrom.getRangeAddress())
oSheet.getColumns.removeByIndex(iToBeRemoved, 1)
End Sub
That is for a single column, but could be enhanced to deal with multiple
columns and rows.
Anyone who are interested in writing code for the following behavior?
1. choose a certain cell or cells.
2. Ctrl-Alt-Arrow Key (up, down, left, or right)
3. the the column(s) or row(s) that accommodates the selected cells goes around
as directed by the arrow key.
That could be similar behavior as Writer does with Ctrl-Alt-Up or Down arrow
key to move the paragraph up or down as if the paragraph is freely swimming on
the document.
Thanks in advance,
Tora
On 2011/06/16 17:55, Martin Hediger wrote:
Thanks for the feedback, indeed it makes intuitively sense to check out that
part of the API.
The simplest way of defining the rows to exchange (that I can think of right
now) would be to just to select two rows in the spreadsheet. If more or less
than two rows are selected, this would cause an exception.
Martin
On 16.06.11 10:42, Niklas Nebel wrote:
On 15.06.2011 23:19, Martin Hediger wrote:
I was thinking, would it be possible to implement some kind of row-row
exchange button in Calc? Of course, the same could apply to
column-column exchange.
It depends on the desired behavior of that button. Probably it can be a combination of "insert
rows", "move cells" and "delete rows". These are all available via API, so it can be
implemented as an extension. How do you want to select the rows to exchange?
Anyway, would be cool if someone could point me out to some part of the
code where one might start looking at this.
See http://wiki.services.openoffice.org/wiki/Extensions_development for general
information about extension development.
Niklas
--
-----------------------------------------------------------------
To unsubscribe send email to dev-unsubscr...@openoffice.org
For additional commands send email to sy...@openoffice.org
with Subject: help