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

Brainstorming, With script, How to transform spread rows into HEADER_ROWS or to BODY_ROWS?

Guide ,
Aug 07, 2025 Aug 07, 2025

666.png

 

God of all gods, come up with an good idea together.

 

Hi m1b.

I am sorry, I still couldn't help myself. Confusion is torture.

When there is only one row in the header, it can be directly converted to a header.
like this:

var doc = app.activeDocument,
selectedRows = getRows(doc.selection[0]);
var headerRows = convertToRowType(selectedRows, RowTypes.HEADER_ROW);

 

But when there are cross row columns, conversion is not allowed.

Sometimes it needs to be converted to BODY_ROWS, and sometimes it needs to be converted to HEADER_ROWS.

 

TOPICS
Bug , Scripting
1.4K
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

correct answers 1 Correct answer

Community Expert , Aug 28, 2025 Aug 28, 2025

Hi @dublove ,

please do comments on my code here in this thread and not in a different one.

You said in this other thread:

 

"The code doesn't make sense, my goal is to identify the selected row (and then I'll do the table header conversion).
But it seems to return the selected table?"

 

https://community.adobe.com/t5/indesign-discussions/extendscript-how-to-convert-selected-table-rows-to-header/m-p/15295053#M622593

 

In this very thread you said:

"My true purpose is add:
Step 2: Convert the selec

...
Translate
Guide ,
Aug 08, 2025 Aug 08, 2025

Hi @Manan Joshi 

Maybe you have a good idea about this.

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 ,
Aug 26, 2025 Aug 26, 2025

Hi @dublove ,

with a selection of cells or rows in mind, you could try to undo the merge with a menu command, in scripting terms, a menuAction. The menu action's name for merging selected table cells is "$ID/kTablesMenuMerge Cells_&", for unmerging selected table cells is "$ID/kTablesMenuUnmerge Cells_&".

 

So, basically, if the two table rows are already selected, unmerging them in one go would be:

app.menuActions.itemByName( "$ID/kTablesMenuUnmerge Cells_&" ).invoke();

 

Before running the script code above:

Bildschirmfoto 2025-08-26 um 14.18.59.png

After running the script:

Bildschirmfoto 2025-08-26 um 14.19.53.png

The same result applies if both selected rows are header rows.

 

If the text frame is selected, not the table's two rows, you could run this script to unmerge all cells in the first two rows:

var textFrameHoldingTheTable = app.selection[0];
var table = textFrameHoldingTheTable.parentStory.tables[0];

var row1 = table.rows[0];
var row2 = table.rows[1];

app.select( row1 );

app.menuActions.itemByName( "$ID/kTablesMenuUnmerge Cells_&" ).invoke();

app.select( row2 );

app.menuActions.itemByName( "$ID/kTablesMenuUnmerge Cells_&" ).invoke();

 

Note, it's not that easy, maybe impossible, to select the first two rows of this special case in one go by scripting.

 

Regards,
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 ,
Aug 26, 2025 Aug 26, 2025

@Laubender 

Step 1: Undoing all merges is one thing.

Step 3: More importantly, you must also restore the original state before merging.

 

My true purpose is  add:
Step 2: Convert the selected rows into 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
Community Expert ,
Aug 27, 2025 Aug 27, 2025

Hi @dublove ,

well, if Step 2 is your problem, convert the selected rows into HEADER_ROW, you can do this without unmerging the cells by adding another menu action to my script above.

 

When the text frame that is holding the table is selected, just run the following code:

var textFrameHoldingTheTable = app.selection[0];
var table = textFrameHoldingTheTable.parentStory.tables[0];

var row1 = table.rows[0];
var row2 = table.rows[1];

app.select( row1 );

app.menuActions.itemByName( "$ID/kTablesMenuUnmerge Cells_&" ).invoke();
app.menuActions.itemByName( "$ID/To Header" ).invoke();


app.select( row2 );

app.menuActions.itemByName( "$ID/kTablesMenuUnmerge Cells_&" ).invoke();
app.menuActions.itemByName( "$ID/To Header" ).invoke();

 

PS: It does not work without unmerging the cells. Had to edit my post.

 

Regards,
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
Community Expert ,
Aug 27, 2025 Aug 27, 2025

However, if the user's selection is already the first two rows with merged cells, the menu action for converting rows to header rows will do:

app.menuActions.itemByName( "$ID/To Header" ).invoke();

 

Regards,
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
Community Expert ,
Aug 27, 2025 Aug 27, 2025

Hi @dublove ,

I think I resolved your issue. Start out with the selected text frame that is holding the table where the first two rows of the table contain merged cells and should be converted to header rows. Just run the following script on the selected text frame:

var textFrameHoldingTheTable = app.selection[0];
var table = textFrameHoldingTheTable.parentStory.tables[0];

var row1 = table.rows[0];
var row2 = table.rows[1];

// Copy the selected table to the clipboard:
app.select( table );
app.copy();

// Now work on the two body rows:
app.select( row1 )

app.menuActions.itemByName( "$ID/kTablesMenuUnmerge Cells_&" ).invoke();
app.menuActions.itemByName( "$ID/To Header" ).invoke();

app.select( row2 );

app.menuActions.itemByName( "$ID/kTablesMenuUnmerge Cells_&" ).invoke();
app.menuActions.itemByName( "$ID/To Header" ).invoke();

// Finally paste the contents of the clipboard, the table with the merged cells, 
// to the selected table:
app.select( table );
app.paste();

 

Regards,
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
Community Expert ,
Aug 28, 2025 Aug 28, 2025

Hi @dublove ,

please do comments on my code here in this thread and not in a different one.

You said in this other thread:

 

"The code doesn't make sense, my goal is to identify the selected row (and then I'll do the table header conversion).
But it seems to return the selected table?"

 

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

 

In this very thread you said:

"My true purpose is add:
Step 2: Convert the selected rows into HEADER_ROW."

 

That's the most easiest thing to do with a single menu action:

app.menuActions.itemByName( "$ID/To Header" ).invoke();

 

Regards,
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 ,
Aug 28, 2025 Aug 28, 2025
LATEST

Hi Laubender

I've successfully implemented the attack using the m1b method.

I've been extremely busy lately.


Thanks, I'll try your menu method when I have time.
It seems easier.

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