Page 1 of 1

Flipping Tables

Posted: 2013-11-02 01:43:40
by phspaelti
NWP 2.0.5 introduced a number of new features for dealing with tables in macros. The following macro takes advantage of these features to improve on previous macros.

This macro will flip a table's rows and columns. It works for tables with different numbers of rows and columns, and it also works with tables that have merged cells. it also copies cell edge attributes, and it tries to preserve the size of the table and the relative widths and heights of the rows and columns, as far as possible.
Swap Rows and Columns.nwm
(22.93 KiB) Downloaded 192 times
Update: found yet another small bug. But fixed now.

Re: Flipping Tables

Posted: 2013-11-02 05:48:32
by NisusUser
Hi, Philip,

Good to see you're still practicing macro-writing :)

I tried this macro on a table (3x3) and it didn't work. Just left a shrunken table in the middle of the page. So then I inserted a table with no left upper box usable and tried the macro on it. Still doesn't work (same result).

Re: Flipping Tables

Posted: 2013-11-02 06:34:19
by phspaelti
Thanks Eric.

The problem seems to be that Nisus treats the rows of a default table as having a height of 0. In such cases the layout engine seems to adjust the height as necessary. But my macro sets the dimensions (the width of the new table) according to that number. So you end up with a 0 width table. You could avoid that result by adjusting the height manually. That forces the table to take on a fixed height and the problem is solved.

Well, to avoid these complications I have replaced the macro with a version that automatically forces the height to be 1 in such cases. It's a kludge, but a small one :)

Re: Flipping Tables

Posted: 2013-11-02 06:50:17
by NisusUser
Beautiful! Works as described! Way to go!