Copy link to clipboard
Copied
If the table header row is only one row, this script seems to work.
But if there are two table header rows, this header is again basically dizzy and hopeless.
dupeTopRow(myTable);
myTable.rows.add(LocationOptions.BEFORE, myTable.rows[0]);
/**
* duplicate the first row af a myTable
* @ param the myTable
* @ return void
*/
function dupeTopRow(t){
var newRow = t.rows.add(LocationOptions.BEFORE, t.rows[0]);
var newCell = newRow.cells
var lr = t.rows[1].cells
for (var i = 0; i < newCell.length; i++){
newCell[i].properties = lr[i].properties;
};
Copy link to clipboard
Copied
Hi @dublove ,
your code will not work.
Because it will add a new row before the header row. And that automatically becomes an additional header row.
An additional body row must be added after the last header row.
Why? A table cannot start with a body row followed by a header row.
So what, I have to ask, will you like to do?
Converting all header rows to body rows because you want to add a body row at the start of your table?
Or do you want a new body row before the first body row and leave all header rows as they are?
Please explain.
Thanks,
Uwe Laubender
( Adobe Community Expert )
Copy link to clipboard
Copied
Hi @Laubender
I want to copy the header row and make a fake header row on page 1. The real table header row is on page 2.
This script deals with one row, but I don't know how to deal with it if there are 2 rows of header rows.
Thank you.
Copy link to clipboard
Copied
I'm not really sure what you're asking - but there's a way to skip header rows in the Table Options
You can skip headers in Tables - here I skipped the header rows - so it's in 2nd row now
Start with something like this
Then change the setting
Then it skips automatically - so you can put whatever you want in the first one
The 2nd one controls the headers, so changing the 2nd one would change the 3rd column
Copy link to clipboard
Copied
I would use the script on how to skip the header rows of the table.
I am now trying to copy the table header rows.
If the table header row is only 1 row, I will use the script above.
But if the table header row has 2, or 3 rows, I won't know how to use the script to solve it.
Why would I do that? Because I want to put the words “continue tab” at the top of page 2.
Copy link to clipboard
Copied
I've no idea what you're trying to do - can you show a before and after
And highlight where it's not working.
Copy link to clipboard
Copied
This one is complicated to say the least, as my script is a massive amount of work.
Like this code that m1b helped write.
I really just want the table header to be selected and then I can control it.
You don't have to bother with that.
I just want to use the script to copy the table header rows right now, for example, the original table header rows had 2 rows, now I want to copy them to get 4 rows, and then I'm going to be converting rows[0] rows[1] to table header rows. And rows[2],rows[3] act as “fake” headers for page 1.
Copy link to clipboard
Copied
I have replaced the sample file.
Do I need to cancel the table header first?
I get a little dizzy when I run into circular judgments, especially nested ones.
Copy link to clipboard
Copied
I'll take a look Monday - too much going on at the moment. Hopefully it can be resolved for you.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Turns out I never found a reasonable thought.
This idea is either clearer and more reasonable:
Select the header rows (or what will be header rows), convert them to body rows, then copy them, and then convert the original header rows at the top to header rows.
Copy link to clipboard
Copied
A piece of code originally provided by m1b, perhaps not needing a backward-looking one, just to get the mouse-selected row.
Wouldn't it be simple to convert the table pair rows to body rows, but after copying, I don't know how to get back the original table header rows.
Don't see what's wrong, but no reaction.
Maybe I just need to get the value of selectedRows.length.
But it seems that this value is not obtained.
* m1b
* 2025-05-01
* @discussion https://community.adobe.com/t5/indesign-discussions/how-can-i-accurately-perform-a-table-header-row-conversion-operation-with-a-script/m-p/15295606
*/
*/
function main() {
var doc = app.activeDocument,
selectedRows = getRows(doc.selection[0]);
if (0 === selectedRows.length)
return alert('Please select some table rows and try again.')
// convert the selected rows to header rows
var myTable=selectedRows.parent;
var le=selectedRows.length;
//if ((firstRow.rowType !== RowTypes.HEADER_ROW) && (myTable.rows[0].cells[0].contents !==contName))
// {
dupeTopRow(myTable);
function dupeTopRow(t){
for(j=0;j<selectedRows.length;++j){
var newRow = t.rows.add(LocationOptions.BEFORE, t.rows[0]);
var newCell = newRow.cells
var lr = t.rows[le+j-1].cells
for (var i = 0; i < newCell.length; i++){
newCell[i].properties = lr[i].properties;
};
}
}
//else{
//alert("Header is exsit")
//exit ();
//}
//}
Copy link to clipboard
Copied
Take two rows as an example.
The basic logic should look like this
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
It's just a matter of copying multiple rows of the table, I'm copying from back to front.
Turns out I didn't turn this corner.
I'm having a headache with loops.
le = headerRows[headerRows.length-1].index;
dupeTopRow(myTable);
function dupeTopRow(t){
for(j=0;j<=le;++j){
var newRow = t.rows.add(LocationOptions.BEFORE, t.rows[0]);
var newCell = newRow.cells
var lr = t.rows[le+1].cells
for (var i = 0; i < newCell.length; i++){
newCell[i].properties = lr[i].properties;
};
}
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now