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

There are two table header rows, what is the script to copy these two rows as normal rows?

Guide ,
Jun 06, 2025 Jun 06, 2025

 

 

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;
    };   

 

TOPICS
Bug , Feature request , How to , Scripting
330
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
Community Expert ,
Jun 06, 2025 Jun 06, 2025

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 )

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 ,
Jun 06, 2025 Jun 06, 2025

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.

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
Community Expert ,
Jun 06, 2025 Jun 06, 2025

I'm not really sure what you're asking - but there's a way to skip header rows in the Table Options 

 

Screenshot 2025-06-06 at 17.40.02.png

 

You can skip headers in Tables - here I skipped the header rows - so it's in 2nd row now

 Start with something like this

Screenshot 2025-06-06 at 17.40.02.png

 

Then change  the setting

Screenshot 2025-06-06 at 17.40.09.png

 

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

 

 

Screenshot 2025-06-06 at 17.42.23.png

 

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 ,
Jun 06, 2025 Jun 06, 2025

@Eugene Tyson 

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.

 

 

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
Community Expert ,
Jun 06, 2025 Jun 06, 2025

I've no idea what you're trying to do - can you show a before and after 
And highlight where it's not working.

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 ,
Jun 06, 2025 Jun 06, 2025

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.

226.png

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 ,
Jun 07, 2025 Jun 07, 2025

Hi @Eugene Tyson 

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.

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
Community Expert ,
Jun 07, 2025 Jun 07, 2025

I'll take a look Monday  - too much going on at the moment. Hopefully it can be resolved for you.

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 ,
Jun 09, 2025 Jun 09, 2025

HI @Eugene Tyson 

Looking forward to your care.

Thank you very much.

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 ,
Jun 10, 2025 Jun 10, 2025

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.

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 ,
Jun 10, 2025 Jun 10, 2025

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.

 

https://community.adobe.com/t5/indesign-discussions/extendscript-how-to-convert-selected-table-rows-... 

 

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 ();
//}
//}

 

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 ,
Jun 10, 2025 Jun 10, 2025

Take two rows as an example.
The basic logic should look like this

28.png

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 ,
Jun 12, 2025 Jun 12, 2025

Hi Eugene Tyson

No need to research this.

I solved some problems.
Thank you very much~

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
Community Expert ,
Jun 12, 2025 Jun 12, 2025

@dublove said: "… 

No need to research this.

I solved some problems."

 

Hi @dublove ,

can you share some code how exactly you did it?

 

Thanks,
Uwe Laubender
( Adobe Community Expert )

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 ,
Jun 12, 2025 Jun 12, 2025
LATEST

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;
                    };   
            }
        }

 

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