0
var doc = app.activeDocument,
_pages = doc.pages, i, j, k, l,
_textframes, _tables, _row, _cell, rownum;
for (i = 0; i < _pages.length; i++) {
    _tables = _pages.item(i).Tables;
    for (j = 0; j < _tables.length; j++) {
        _row = _tables.item(i).rows;
        rowlen = _row.length;
        for (k = 0; k < _row.length; k++) {
            _cell = _row.item(i).cells;
            for (l = 0; l < _cell.length; l++) {
            _cell.item(i).appliedCellStyle = "CellA";
            _cell.item(i).paragraphs.everyItem().appliedParagraphStyle = "ParA"; 
            }
        }
     }
}

Hi, I am relatively new to Indesign scripting and I aim at writing a script that will format all cells of the table so I wrote one. But the above script only formats first cell of first row. The other problem is that it finds only one cel in each row.

user3386167
  • 65
  • 1
  • 1
  • 6
  • 1
    As has been [noticed elsewhere](https://forums.adobe.com/thread/1511743), there are a couple of basic errors in your code. The more reason to *keep it in one forum*; that way, others' remarks can be used in an answer. – Jongware Jul 01 '14 at 17:40

1 Answers1

1

Problem is with loops, you have 4 loops but selecting items only by i that is 'topmost' loop used to iterate pages, what you should do is use j in the loop for tables, k for rows and l for cells.

var doc = app.activeDocument,
_pages = doc.pages, i, j, k, l,
_textframes, _tables, _row, _cell, rownum;
for (i = 0; i < _pages.length; i++) {
    _tables = _pages.item(i).Tables;
    for (j = 0; j < _tables.length; j++) {
        _row = _tables.item(j).rows;
        rowlen = _row.length;
        for (k = 0; k < _row.length; k++) {
            _cell = _row.item(k).cells;
            for (l = 0; l < _cell.length; l++) {
            _cell.item(l).appliedCellStyle = "CellA";
            _cell.item(l).paragraphs.everyItem().appliedParagraphStyle = "ParA"; 
            }
        }
     }
}
Matas Vaitkevicius
  • 58,075
  • 31
  • 238
  • 265