Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to set row type in all the tables?

New Here ,
May 30, 2016 May 30, 2016

I need to convert first row of all the tables to header row. I tried all the possible ways which are mentioned below, but am getting the error (can't set row type) . After researched about this error I got to know that this is a read only property so can't change row type in a table. How can I fix this?

1.

var myTables = app.activeDocument.stories.everyItem().tables; 

 

for (var i = 0; i < myTables.length; i++) { 

    myTables.rows.firstItem().rowType = RowTypes.HEADER_ROW; 

}

2.

  app.activeDocument.stories.everyItem().tables.everyItem().rows[0].rowType=RowTypes.HEADER_ROW;  

3.

var myRows = app.activeDocument.stories.everyItem().tables.everyItem().rows[0].getElements(), 

      myCells = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem(), 

      l = myRows.length; 

while (l--) if (myRows.rowType == RowTypes.BODY_ROW) myRows.rowType = RowTypes.HEADER_ROW;

      

TOPICS
Scripting
605
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
May 30, 2016 May 30, 2016

Your first method itself working fine for me..

var myTables = app.activeDocument.stories.everyItem().tables;

for (var i = 0; i < myTables.length; i++) {

    myTables.rows.firstItem().rowType = RowTypes.HEADER_ROW;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
May 30, 2016 May 30, 2016
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 30, 2016 May 30, 2016

Thanks Karthi for the code and the links!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
May 30, 2016 May 30, 2016

Share the error screen please

PS: Obi-wan Kenobi, i copied OP code not mine

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 30, 2016 May 30, 2016

Oups! 😉

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 30, 2016 May 30, 2016
LATEST

I have not read the other posts, but the first code fails, because 'myTables.rows.firstItem()' repesents not the result of one row!

The second code ' app.activeDocument.stories.everyItem().tables.everyItem().rows.firstItem().rowType = RowTypes.HEADER_ROW; '

fails, if there is already one table with a header row.

So I would do it in this way:

var myTables = app.activeDocument.stories.everyItem().tables.everyItem().getElements();

for (var i = 0; i < myTables.length; i++) {

  var curTable = myTables;

  var firstRow = curTable.rows[0];

  if (firstRow.rowType != RowTypes.HEADER_ROW) {

    firstRow.rowType = RowTypes.HEADER_ROW;

  }

}

Kai

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 30, 2016 May 30, 2016

But am getting ERROR: Can't set row type

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines