Copy link to clipboard
Copied
My table header usually has 1-4 rows, most of the time 1-2rows.
I sometimes need to determine which table header rows already exist.
Next I need to convert to body rows, or copy the table header rows.
Before I applied the style, I determined the number of table headers by manually selecting them.
The table header rows are the rows I selected.
How should this code be expressed?
After applying table styles, if I ever have table headers.
How do I determine which rows are table headers?
Okay @dublove you just want a script to simply convert the selected cells to header rows and other rows to body rows. Easy right? Haha, here you go...
- Mark
/**
* @file Convert Table Row Types.js
*
* Will convert the selected rows to header rows
* and also convert any non-selected header rows
* to body rows.
*
* Note: will convert the minimum number of rows
* necessary to obey the rules around converting rows
* with merged cells. This may be *more* than the
* selected rows.
*
* @a...
Copy link to clipboard
Copied
Edit 2025-08-26: updated getRows function.
I was in high spirits all day.
It still seems unable to switch to BODY_ROW.
No prompts are displayed.
By all accounts, this success:
function toHeader() {
var doc = app.activeDocument,
selectedRows = getRows(doc.selection[0]);
var headerRows = convertToRowType(selectedRows, RowTypes.HEADER_ROW);
};
toHeader();That body should be fine like this:
toBody();
function toBody() {
var doc = app.activeDocument,
selectedRows = getRows(doc.selection[0]);
if (0 === selectedRows.length)
return alert('Please select some table rows and try again.')
//var headerRows = convertToRowType(selectedRows, RowTypes.HEADER_ROW);
//var bodyRows = [],
// table = headerRows[0].parent,
// lastHeaderRowIndex = headerRows[headerRows.length - 1].index;
//for (var i = lastHeaderRowIndex + 1; i < table.rows.length; i++)
// if (RowTypes.HEADER_ROW === table.rows[i].rowType)
// bodyRows.push(table.rows[i]);
//var bodyRows = convertToRowType(bodyRows, RowTypes.BODY_ROW);
var bodyRows = convertToRowType(selectedRows, RowTypes.BODY_ROW);
}
However, the third line below returned an error: Unable to set row type.
for (var i = 0; i < rows.length; i++)
if (rows[i].rowType !== rowType)
rows[i].rowType = rowType;
Copy link to clipboard
Copied
lastHeaderRowIndex + 1 makes no sense.
This must already be BODY_ROW. Unselected rows don't need conversion.
for (var i = lastHeaderRowIndex + 1; i < table.rows.length; i++)
alert(i);
if (RowTypes.HEADER_ROW === table.rows[i].rowType)
bodyRows.push(table.rows[i]);Should be changed to:
for (var i = lastHeaderRowIndex; i >= 0; i--)
alert(i)
if (RowTypes.HEADER_ROW === table.rows[i].rowType)
bodyRows.push(table.rows[i]);
Just make the change here.
Two are needed here. But I don't know how to make the front automatically determine which one to select.
if (to == "RB") {
// R to B set the rowType of each row
for (var i = rows.length - 1; 0 <= i; i--) {
if (rows[i].rowType !== rowType)
rows[i].rowType = rowType;
}
}
if (to == "BR") {
// B to R set the rowType of each row
for (var i = 0; i < rows.length; i++) {
if (rows[i].rowType !== rowType)
rows[i].rowType = rowType;
}
}
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Just make the changes as I instructed.
The m1b version is already good.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
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?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now