[dev] Re: Implementation of Row Exchange Button in Calc
Am 17.06.2011 17:38, tora - Takamichi Akiyama wrote: On 2011/06/17 16:38, Martin Hediger wrote: Its true, i havent thought of the implications of what it means to switch rows. Should references pointing to cell A1 remain pointing to A1, when the content of A1 is traded for the content of B1? What should the references follow? But apart from that, the way to exchange two rows is I believe indeed achieved most easily by a combination of the insert_row(), move_row(), delete_row() methods. If you want to swap the contents of two rows or columns but you do not want to change their references, it might be a set of 1. insert_row as a temporal space, 2. COPY_row 1 to the temporal space, 3. COPY_row from 2 to 1, 4. COPY_row from the temporal row to 2, 5. and delete_row the temporal space. Select the cell range, row or column. Drag the cell selection (not the column/row header). Hold the Alt key before you drop. -- - To unsubscribe send email to dev-unsubscr...@openoffice.org For additional commands send email to sy...@openoffice.org with Subject: help
[dev] Re: Implementation of Row Exchange Button in Calc
Its true, i havent thought of the implications of what it means to switch rows. Should references pointing to cell A1 remain pointing to A1, when the content of A1 is traded for the content of B1? What should the references follow? But apart from that, the way to exchange two rows is I believe indeed achieved most easily by a combination of the insert_row(), move_row(), delete_row() methods. Doing this in Python would be a nice exercise. Thanks again for the feedback. On 16.06.11 14:16, tora - Takamichi Akiyama wrote: 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
[dev] Re: Implementation of Row Exchange Button in Calc
Hi Oliver, On 2011/06/17 1:12, Oliver Brinzing wrote: Quickly move Rows and columns like in Writer http://openoffice.org/bugzilla/show_bug.cgi?id=40285 have a look at the attached example ;-) Thanks! That is what I thought. And now, I also have written a similar one. ;-) https://bitbucket.org/tora/calc-move-selected-cells/src/tip/src/calc-move-selected-cells.bas.txt Best regards, Tora -- - To unsubscribe send email to dev-unsubscr...@openoffice.org For additional commands send email to sy...@openoffice.org with Subject: help
[dev] Re: Implementation of Row Exchange Button in Calc
Oops, there was a typo bug. Now fixed: https://bitbucket.org/tora/calc-move-selected-cells Best, Tora On 2011/06/17 23:40, tora - Takamichi Akiyama wrote: Hi Oliver, On 2011/06/17 1:12, Oliver Brinzing wrote: Quickly move Rows and columns like in Writer http://openoffice.org/bugzilla/show_bug.cgi?id=40285 have a look at the attached example ;-) Thanks! That is what I thought. And now, I also have written a similar one. ;-) https://bitbucket.org/tora/calc-move-selected-cells/src/tip/src/calc-move-selected-cells.bas.txt Best regards, Tora -- - To unsubscribe send email to dev-unsubscr...@openoffice.org For additional commands send email to sy...@openoffice.org with Subject: help
[dev] Re: Implementation of Row Exchange Button in Calc
On 2011/06/17 16:38, Martin Hediger wrote: Its true, i havent thought of the implications of what it means to switch rows. Should references pointing to cell A1 remain pointing to A1, when the content of A1 is traded for the content of B1? What should the references follow? But apart from that, the way to exchange two rows is I believe indeed achieved most easily by a combination of the insert_row(), move_row(), delete_row() methods. If you want to swap the contents of two rows or columns but you do not want to change their references, it might be a set of 1. insert_row as a temporal space, 2. COPY_row 1 to the temporal space, 3. COPY_row from 2 to 1, 4. COPY_row from the temporal row to 2, 5. and delete_row the temporal space. It might look like: int a = 1; int b = 2; int t; t = a; a = b; b = t; Best regards, Tora -- - To unsubscribe send email to dev-unsubscr...@openoffice.org For additional commands send email to sy...@openoffice.org with Subject: help
[dev] Re: Implementation of Row Exchange Button in Calc
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
[dev] Re: Implementation of Row Exchange Button in Calc
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
[dev] Re: Implementation of Row Exchange Button in Calc
Hi, maybe this can help: Quickly move Rows and columns like in Writer http://openoffice.org/bugzilla/show_bug.cgi?id=40285 have a look at the attached example ;-) Regards Oliver -- GnuPG key 0xCFD04A45: 8822 057F 4956 46D3 352C 1A06 4E2C AB40 CFD0 4A45 signature.asc Description: OpenPGP digital signature