Hi @dublove5CFE, here's a script to do what you want I think.
- Mark
/**
* Adjust selected tables.
* @author m1b
* @discussion https://community.adobe.com/t5/indesign-discussions/can-you-help-me-write-a-script-for-table-which-can-save-a-lot-of-work/m-p/13861606
*/
function main() {
var doc = app.activeDocument,
tables = getSelectedTables(doc),
tableStyle = getByName(doc.allTableStyles, 'Tabs'),
footerStyle = getByName(doc.allCellStyles, 'Footer');
if (tables.length == 0)
alert('No tables selected.');
for (var i = tables.length - 1; i >= 0; i--) {
var table = tables[i];
// apply table style
table.appliedTableStyle = tableStyle;
// set all rows height
table.rows.everyItem().autoGrow = true;
table.rows.everyItem().minimumHeight = '10mm';
// convert first row to header
if (table.rows[0].rowType == RowTypes.BODY_ROW)
table.rows[0].rowType = RowTypes.HEADER_ROW;
// adjust footer row
var footerRow = table.rows.lastItem();
if (footerRow.contents.join('').length > 0)
footerRow = table.rows.add();
if (footerRow.rowType !== RowTypes.FOOTER_ROW)
footerRow.rowType = RowTypes.FOOTER_ROW;
footerRow.autoGrow = false;
footerRow.height = '1.058mm';
footerRow.cells.everyItem().appliedCellStyle = footerStyle;
}
};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Adjust Tables');
/**
* Returns array of Tables,
* based on document's selection.
* @author m1b
* @version 2023-06-15
* @param {Document} doc - an Indesign Document.
* @returns {Array<Table>}
*/
function getSelectedTables(doc) {
if (
doc == undefined
|| doc.selection == undefined
)
return [];
var sel = doc.selection,
tables = [];
for (var i = 0; i < sel.length; i++) {
if (sel[i].hasOwnProperty('tables'))
for (var j = 0; j < sel[i].tables.length; j++)
tables.push(sel[i].tables[j]);
if (sel[i].parent.constructor.name == 'Table')
tables.push(sel[i].parent);
if (sel[i].parent.parent.constructor.name == 'Table')
tables.push(sel[i].parent.parent);
if (sel[i].constructor.name == 'Table')
tables.push(sel[i]);
}
return tables;
};
/**
* Returns a style matching name.
* @author m1b
* @version 2022-08-14
* @param {Array<style>} styles - an array or collection of styles.
* @param {String} name - the name to match.
* @returns {style}
*/
function getByName(styles, name) {
for (var i = 0; i < styles.length; i++)
if (styles[i].name == name)
return styles[i];
};
Edit 2023-06-14: set all rows' heights and footer row's height.
Edit 2023-06-15: now correctly adds footer row.
Edit 2023-06-15: footer row only added if last row isn't empty. Improved getSelectedTables function.
Edit 2023-06-16: now correctly adjusts footer row even if already a footer row.