Editing table cell borders

Get help using and writing Nisus Writer Pro macros.
Post Reply
ThosGreen
Posts: 16
Joined: 2021-09-15 03:28:09

Editing table cell borders

Post by ThosGreen »

I wish to change the borders of a cell in a table. The code I have tried is:

Code: Select all

Select Table 1
$thisTable = Table.selectedTable
$aCell = $thisTable.cellAtRowAndColumn 1, 1
$aCell.setLineAttributesForEdges 'invisible', 'top'

I have experimented with various combinations of capitals (Invisible/invisible) and single/double/no quotes, but all i get is error messages like these:
  • unexpected text in macro source code
    invalid variable assignment
    Expected a value of type LineAttributes, found Text.
I know that I'm successfully finding a cell because I have been able to change the text in the cell, so it's something to do with the

Code: Select all

setLineAttributesForEdges
command. Does anyone know the correct syntax, please?

Also: can I change the whole table at one go, or do I have to write a couple of loops to address every cell and change its borders individually?

Thanks in advance.
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Editing table cell borders

Post by phspaelti »

As the message says you need a line attribute object not text:

Code: Select all

Select Table 1
$thisTable = Table.selectedTable
$aCell = $thisTable.cellAtRowAndColumn 1, 1
$lineAttr = LineAttributes.newWithLineType 'invisible'
$aCell.setLineAttributesForEdges $lineAttr, 'top'
You can, if you prefer combine it like this:

Code: Select all

Select Table 1
$thisTable = Table.selectedTable
$aCell = $thisTable.cellAtRowAndColumn 1, 1
$aCell.setLineAttributesForEdges LineAttributes.newInvisible, 'top'
Last edited by phspaelti on 2022-10-30 04:34:50, edited 1 time in total.
philip
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Editing table cell borders

Post by phspaelti »

ThosGreen wrote: 2022-10-30 00:26:19Also: can I change the whole table at one go, or do I have to write a couple of loops to address every cell and change its borders individually?
Yes, you can change the whole table in one go. For that you should work with table selections.
For example:

Code: Select all

$doc = Document.active
Select Table 1
$tblSel = $doc.tableSelection
$lineAttr = LineAttributes.newInvisible
$tblSel.applyLineAttributesToEdges $lineAttr, 'all'
Note the fine-grained syntax :wink: , for cells it's "set … for" and for table selections it's "apply … to"
Also see the macro reference for the welter of arguments to describe the affected edges.
philip
ThosGreen
Posts: 16
Joined: 2021-09-15 03:28:09

Re: Editing table cell borders

Post by ThosGreen »

@phspaelti - Bingo. Thanks.

You can do wonders with Nisus macros but a few more examples in the docs might be useful :)
Post Reply