Skip to main content
Participating Frequently
November 9, 2023
Question

Tabellen: Nach Überlauftext suchen und Zellenhöhe anpassen

  • November 9, 2023
  • 2 replies
  • 773 views

Hallo zusammen,

nachdem mir hier in dieser Diskussion super geholfen wurde habe ich eine neue Anfrage:

Ich habe oftmals Tabellen mit 1-3000 Zeilen. Die Zellenhöhe ist fix definiert und wird für die gesamte Tabelle angepasst.

Wenn ich nun den Text in die Tabelle einlade, gibt es etliche Zelleninhalte, die Überlauftext haben, der nciht angezeigt wird (nur mit dem roten Punkt am Ende der Zelle). 

Wie kann ich für diese Zellen mit Suchen&Ersetzen eine doppelte Zellenhöhe zuweisen, damit der Text in die Zelle passt? Geht das per GREP oder nur mit einem Script (von dem ich immer noch keine Ahnung habe... 🫢)

vg

 

This topic has been closed for replies.

2 replies

m1b
Community Expert
Community Expert
November 9, 2023

Hi @jdh2023, when you say that you want a cell to have double row height, do you mean the whole row will have double row height? Or do you want to merge the cell with the cell below it to make just that cell double row height (and the below cell is gone)?

- Mark

Known Participant
November 10, 2023

Hello m1b,
the lines should be double height, not merged.
In addition, the heights of the cells vary from table to table, sometimes the rows are 4mm high, sometimes only 3.8mm and, accordingly, with two lines then 8mm or 7.6mm...

m1b
Community Expert
Community Expert
November 10, 2023

Hi @jdh_gd, I've written a quick script to do that. It reads the height of the first body row and uses that to dictate the heights of all the other body rows. For example:

/**
 * Set table row heights to a factor of the row height
 * of first body row of table.
 * @author m1b
 * @discussion https://community.adobe.com/t5/indesign-discussions/tabellen-nach-überlauftext-suchen-und-zellenhöhe-anpassen/m-p/14225092
 */

function main() {

    var doc = app.activeDocument;
    if (doc.selection.length == 0)
        return alert('Please select one or more tables and run script again.');

    var tables = getTables(doc.selection),
        rowHeight;

    tablesLoop:
    for (var i = 0; i < tables.length; i++) {

        rowsLoop:
        for (var r = 0; r < tables[i].rows.length; r++) {

            var row = tables[i].rows[r];

            if (row.rowType == RowTypes.HEADER_ROW)
                // ignore header rows
                continue rowsLoop;

            row.autoGrow = false;

            if (rowHeight == undefined)
                // get the row height of first body row of table
                rowHeight = row.height;

            row.height = rowHeight;

            cellsLoop:
            for (var c = 0; c < row.cells.length; c++)

                // if the cell overflows, expand it by master row height
                while (row.cells[c].overflows) {
                    row.height += rowHeight;
                    row.cells[c].recompose();
                }

        }

    }

};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Set table row heights");



/**
 * Returns array of Tables found in `items`.
 * @author m1b
 * @version 2022-02-01
 * @param {Array<PageItem>} items - the items to look through.
 * @param {Array<Table>} found - private parameter.
 * @returns {Array<Table>}
 */
function getTables(items, found) {
    if (items == undefined) return [];
    if (found == undefined) found = [];
    if (!items.hasOwnProperty('0')) items = [items];

    for (var i = 0; i < items.length; i++) {
        var item = items[i];

        if (
            // item is a table
            item.constructor.name == 'Table'
        ) {
            found.push(item);


        } else if (
            // item contains tables
            item.hasOwnProperty('tables')
            && item.tables.length > 0
        ) {
            found = found.concat(getTables(item.tables));


        } else if (
            // parent is a table cell
            item.hasOwnProperty('parent')
            && item.parent.constructor.name == 'Cell'
        ) {
            found = found.concat(getTables([item.parent.parent]));


        } else if (
            // is in a story, which may contain tables
            item.hasOwnProperty('parentStory')
        ) {
            found = found.concat(getTables([item.parentStory]));


        } else if (
            // contains page items, which may be tables
            item.hasOwnProperty('pageItems')
            && item.pageItems.length > 0
        ) {
            found = found.concat(getTables(item.pageItems));


        } else if (
            // has a parent which might be a table
            item.hasOwnProperty('parent')
            && item.parent.constructor.name != 'Document'
        ) {
            found = found.concat(getTables([item.parent]));

        }
    }

    return found;

};

 

Let me know if that is what you expected. - Mark

Mario Fritsche
Legend
November 9, 2023

Moin,

wenn die Zellenhöhe auf "Mindestens" gestellt sind, sollten sie sich doch von alleine anpassen.

---Mario
Known Participant
November 10, 2023

Moin Mario,

das ist richtig, allerdings kann ich dann die Zeilenhöhen nicht wirklich kontrollieren und die Tabelle »flattert« am unteren Rand aus. Das ist nicht gewünscht und läßt sich nur mir einer fixen Höhe verhindern.