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
987
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
Engaged ,
Aug 07, 2025 Aug 07, 2025

You're working with InDesign scripting and appear to be trying to convert selected rows in a table to header rows.

Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.
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 07, 2025 Aug 07, 2025

HI Anantha Prabu G  

Yes, do you have any good ideas?

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
Engaged ,
Aug 07, 2025 Aug 07, 2025

@dublove 
Credits: @Peter Kahrel (CE)
https://community.adobe.com/t5/indesign-discussions/script-to-convert-first-row-of-table-to-header-r...

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




Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.
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 07, 2025 Aug 07, 2025

@Anantha Prabu G 

You misunderstood me.
You want to convert the currently selected rows to HEADER_ROWS.

What you discussed before was just a simple rows.

This is almost impossible for span rows(spread rows).

 

Ah, m1b understands me best.

dublove_1-1754629336766.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
Community Expert ,
Aug 07, 2025 Aug 07, 2025

Hi @dublove , It sounds like you are expecting row 1 to have 9 cells, but it only has 5:

 

//selected frame’s first table’s first row
var c = app.activeDocument.selection[0].tables[0].rows[0].cells
$.writeln(c.length)
//returns 5
for (var i = 0; i < c.length; i++){
    c[i].fillColor = "Black"
    c[i].fillTint = 20
};

 

Screen Shot 39.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 ,
Aug 07, 2025 Aug 07, 2025

@rob day 

Note that I selected two rows at the same time.
At this point, cross-rows(spead rows) merging is involved. You need to cancel the merge first, then convert to HEADER_ROWS (or BODY_ROWS), and then restore the merge.

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

Hi @rob day 

Come up with a new idea.

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

Not sure what you are trying to do, but if it’s convert the first 2 rows of your example to headers, that throws an error

 
var t = app.activeDocument.stories.everyItem().tables.everyItem().getElements();
$.writeln(t[0].rows[0].rowType)
//returns BODYROW
t[0].rows[0].rowType = RowTypes.HEADER_ROW
//error cannot set row type

 

Screen Shot 41.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 ,
Aug 09, 2025 Aug 09, 2025

This is the key question I want to ask.
When there is cross-rows(spread rows), the table rows do not allow transfers the rows to HEADER_ROWS.

How to solve this bug.

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

@rob day 

Is this possible?
Continue researching this.
Move rows that span columns (spread rows) to the 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 ,
Aug 14, 2025 Aug 14, 2025

Let's all think of ways to solve this problem. Maybe you have a better idea.

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

Hi rob day.

This is a major bug.
m1b has proposed a solution.
First, cancel the cell merge, then restore the merged cells.

This solves the problem of copyable header rows.
However, it still does not solve the problem of converting to HEADER_ROWS.

https://community.adobe.com/t5/indesign-discussions/with-script-how-to-duplicate-header-rows-that-ha...

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

Looks like the error is happening because you have split the rows. If I run this in a table that has not been split:

 

var c = app.activeDocument.stories.everyItem().tables.everyItem().rows.everyItem().getElements()

try {
    c[0].rowType = RowTypes.HEADER_ROW
    c[1].rowType = RowTypes.HEADER_ROW
    alert("Rows 1 & 2 have been converted to headers" )
}catch(e) {
    alert(e)
}    

 

Screen Shot 12.png

 

 

Screen Shot.png

 

Run on your table with split rows:

 

Screen Shot 21.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 ,
Aug 18, 2025 Aug 18, 2025

Hi @rob day 

 

Normal rows without split rows are converted to HEADER_ROWS, which is not difficult.
This is not a problem.

 

The issue we are discussing is:
How to convert split rows to HEADER_ROWS.
How to resolve this bug.

m1b attempted to resolve this by first canceling the merge and then restoring it, but was unsuccessful.

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

Is that possible?
A .First, cancel the merged cells.
B. Then switch to HEADER_ROWS.
C. Finally, restore the merged cells.

 

However, it seems that A to C cannot be interrupted.

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

You would have to create the headers before you merge the cells

 

//get the rows of table 1 of story 1
var r = app.activeDocument.stories[0].tables[0].rows.everyItem().getElements()//

try {
    //set the first 2 rows to headers
    r[0].rowType = RowTypes.HEADER_ROW
    r[1].rowType = RowTypes.HEADER_ROW

    //merge cell 1 of row 1 with cell 1 of row2
    r[0].cells[0].merge(r[1].cells[0])

    alert("Rows 1 & 2 have been converted to headers" )
}catch(e) {
    alert(e)
}    

 

Screen Shot.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 ,
Aug 19, 2025 Aug 19, 2025

Can you convert the table header?
Unable to set row type.

I don't think you understand what I mean.
Wait, let me explain again.

dublove_0-1755615739393.jpeg

 

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

@rob day  @m1b 

What I mean is,
I plan to select the first two rows. Convert their row type to HEADER_ROWS.
Note that I selected them by dragging. But that's not critical to solving this bug. The key is whether the conversion to HEADER_ROWS can be performed during the decomposition process.

If there are no cross-rows, the conversion is fine.

Check out m1b's original post; he set up a function called getRows();
I can get the length of the selected rows, so I can operate on any row.

If there are merged cells, it will prompt that the row type cannot be set.
In m1b's solution, A. first unmerge the cells, C. then merge the cells again.
I think if we can (i.e., after A unmerges the cells), B. immediately convert to HEADER_ROWS, C. then merge the cells again.

That would solve the problem, but A and C seem to be inseparable.

0088-0.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
Community Expert ,
Aug 19, 2025 Aug 19, 2025

This code always fails because the cells are merged before the headers are set

 

//get the rows of table 1 of story 1
var r = app.activeDocument.stories[0].tables[0].rows.everyItem().getElements()//

try {
    r[0].cells[0].merge(r[1].cells[0])
    
    r[0].rowType = RowTypes.HEADER_ROW
    r[1].rowType = RowTypes.HEADER_ROW
    
    alert("Rows 1 & 2 have been converted to headers" )
}catch(e) {
    alert(e)
} 

 

This works on a table with no header rows set or cells merged

 

//get the rows of table 1 of story 1
var r = app.activeDocument.stories[0].tables[0].rows.everyItem().getElements()//

try {
    //set the heads before merging
    r[0].rowType = RowTypes.HEADER_ROW
    r[1].rowType = RowTypes.HEADER_ROW
    
    r[0].cells[0].merge(r[1].cells[0])

    alert("Rows 1 & 2 have been converted to headers" )
}catch(e) {
    alert(e)
}   

 

 

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

@rob day Please refer to my previous reply.

These two pieces of code don't work either.

 

My question is, does it work with span rows?
It should work in all cases.

My goal is to fix the bug.

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

These two pieces of code don't work either.

 

You would have to start with a new table or construct the table via scripting. This makes a new table on page1:

 

//using millimeters
app.scriptPreferences.measurementUnit = MeasurementUnits.MILLIMETERS;//

var d = app.activeDocument
//add a text frame on page 1 of active document
var f = d.textFrames.add ({ geometricBounds: [25,25,150,150]})
//add a 6 column table to the text frame with 2 header rows
var t = f.tables.add ({columnCount:6, bodyRowCount:3, headerRowCount:2, width:125})
//get the rows
var r = t.rows
//merge header cells
r[0].cells[0].merge(r[1].cells[0])
r[0].cells[1].merge(r[1].cells[1])
r[0].cells[2].merge(r[1].cells[1])
//header color
r[0].properties = ({fillColor:"Black", fillTint:20})
r[1].properties = ({fillColor:"Black", fillTint:20})

app.scriptPreferences.measurementUnit = AutoEnum.AUTO_VALUE;

 

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

This is fixed and unchangeable.
It cannot be applied to any table.

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

Hi rob day.

It's still better to cancel the merge based on m1b and then restore it.
Currently, body to header works fine, but header to body doesn't.

 

https://community.adobe.com/t5/indesign-discussions/with-script-how-to-duplicate-header-rows-that-ha...

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

@m1b @rob day 

This operation can be achieved in InDesign.

Then the script should also be able to achieve it?
Perhaps only InDesign developers know the answer to this.

 

Just like how right-clicking an image edited in Photoshop in the Links panel automatically updates it.

626.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