Copy link to clipboard
Copied
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.
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?"
In this very thread you said:
"My true purpose is add:
Step 2: Convert the selec
Copy link to clipboard
Copied
Hi @Manan Joshi
Maybe you have a good idea about this.
Copy link to clipboard
Copied
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:
After running the script:
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 )
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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 )
Copy link to clipboard
Copied
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 )
Copy link to clipboard
Copied
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 )
Copy link to clipboard
Copied
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?"
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 )
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now