Copy link to clipboard
Copied
Hi, so I've used this script a few weeks ago and it worked great. Now for some reason, I'm getting an error "cannot set row type" when running it.
var myTables = app.activeDocument.stories.everyItem().tables;
for (var i = 0; i < myTables.length; i++) {
myTables.rows.firstItem().rowType = RowTypes.HEADER_ROW;
}
All of my tables have a style set with the correct cell styles applied to the table style. I did see another script that said it worked even if some tables already had a header row applied, but that one gave me an error as well.
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;
}
}
Any idea of what might be wrong with it?
Copy link to clipboard
Copied
The second line should be
var curTable = myTables[i];
i.e. add [i] at the end of the line (before the semicolon).
Copy link to clipboard
Copied
Hmmm, that didn't work for me.
var myTables = app.activeDocument.stories.everyItem().tables.everyItem().getElements();
for (var i = 0; i < myTables.length; i++) {
var curTable = myTables[i];
var firstRow = curTable.rows[0];
if (firstRow.rowType != RowTypes.HEADER_ROW) {
firstRow.rowType = RowTypes.HEADER_ROW;
}
}
Copy link to clipboard
Copied
In what way did that not work? An error? No result? Something else?
Copy link to clipboard
Copied
Sorry, I meant to include the error!
Copy link to clipboard
Copied
Well, you could try it like this:
for (var i = 0; i < myTables.length; i++) {
var curTable = myTables[i];
var firstRow = curTable.rows[0];
try {
firstRow.rowType = RowTypes.HEADER_ROW;
} catch (e) {
alert ('Problem in table ' + firstRow.contents);
alert (e);
}
}
If a row can't be converted the alert shows you the content of the first row and the error, so at least you know which table caused the problem. Can you tell from that table what the problem is?
Copy link to clipboard
Copied
I wish I knew what it all meant, I appreciate you helping me out!
Copy link to clipboard
Copied
You should the line at the top that defines myTables:
var myTables = app.activeDocument.stories.everyItem().tables.everyItem().getElements();
Copy link to clipboard
Copied
Still getting an error.
Error String: undefined is not an object
This is what my script looks like:
for (var i = 0; i < myTables.length; i++) {
var myTables = app.activeDocument.stories.everyItem().tables.everyItem().getElements();
var firstRow = curTable.rows[0];
try {
firstRow.rowType = RowTypes.HEADER_ROW;
} catch (e) {
alert ('Problem in table ' + firstRow.contents);
alert (e);
}
}
I think I give up, I'll just manually make them a header row. I don't want to keep bugging you!
Copy link to clipboard
Copied
Don't give up!
It should be like this:
var myTables = app.activeDocument.stories.everyItem().tables.everyItem().getElements();
for (var i = 0; i < myTables.length; i++) {
var firstRow = curTable.rows[0];
try {
firstRow.rowType = RowTypes.HEADER_ROW;
} catch (e) {
alert ('Problem in table ' + firstRow.contents);
alert (e);
}
}
Copy link to clipboard
Copied
I think I'm trying to get as many error strings as possible!
Error String: curTable is undefined
Copy link to clipboard
Copied
Ugh. . . Spot the difference:
var myTables = app.activeDocument.stories.everyItem().tables.everyItem().getElements();
for (var i = 0; i < myTables.length; i++) {
var firstRow = myTables[i].rows[0];
try {
firstRow.rowType = RowTypes.HEADER_ROW;
} catch (e) {
alert ('Problem in table ' + firstRow.contents);
alert (e);
}
}
Copy link to clipboard
Copied
Well now I have a new error! It looks like it's aimed at the titles of my header rows. When I hit OK, I get another box that says Error: cannot set row type. Sure you don't want to give up yet?
Copy link to clipboard
Copied
I take that back. After I posted this, I ran it again, got the same error box. BUT all of my tables now have header rows. I'm stumped but it worked eventually! I can't thank you enough for your help and patience!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now