Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Need urgent help with alternating table fills!

Explorer ,
Jul 21, 2021 Jul 21, 2021

Copy link to clipboard

Copied

On the attached file is a table. In it, I link to an XLSX and apply some styles (para and cells). Now, on import, the table doesn't adopt all these things and the borders etc. need to be removed and formatted... can't seem to bake those into the table style.

Also, the alternating fill I need (white/15%C) SHOULD be white first, after each sub heading. No tables doesn't support subheadings as such so I'm hoping there's a way to make the alternating fill restart after each para style change? Any ideas? All help really appreciated.

TOPICS
How to, Scripting

Views

53

Likes

Translate

Translate

Report

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

Enthusiast , Jul 21, 2021 Jul 21, 2021
Hi @Smallbadger, if Eugene's link (a great article!) doesn't solve your problem I suspect it might be because of your subhead rows, which could complicate things. I've written a quick script to set each row of a table in alternating cell styles, resetting when encountering subhead rows. If you are happy to play with scripting, you may be able to adapt it to your specific needs.To use it you will need to (1) add a new cell style called "BODY ALT", based on "BODY" and give it a cell fill colour of...

Likes

Translate

Translate
Adobe Community Professional ,
Jul 21, 2021 Jul 21, 2021

Copy link to clipboard

Copied

There's a good write up here that will have some excellent tips for you.

https://creativepro.com/preserve-the-appearance-of-text/

 

 

Likes

Translate

Translate

Report

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
Enthusiast ,
Jul 21, 2021 Jul 21, 2021

Copy link to clipboard

Copied

Hi @Smallbadger, if Eugene's link (a great article!) doesn't solve your problem I suspect it might be because of your subhead rows, which could complicate things. I've written a quick script to set each row of a table in alternating cell styles, resetting when encountering subhead rows. If you are happy to play with scripting, you may be able to adapt it to your specific needs.

To use it you will need to (1) add a new cell style called "BODY ALT", based on "BODY" and give it a cell fill colour of 15% cyan (or whatever) *and* set the BODY cell style's fill colour to "[Paper]" (or whatever you want). Once you've done that, select your table and run the script.

Note: The script explicitly applies the "SUBCELL" style to the subhead cells—comment out that line if you don't want this.

 

 

/*
    by m1b
    here: https://community.adobe.com/t5/indesign/need-urgent-help-with-alternating-table-fills/m-p/12190571#M438057
*/

// table cell style names:
var styleName1 = 'BODY',
    styleName2 = 'BODY ALT',
    subheadStyleName = "SUBCELL";


app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Set alternating table styles");

function main() {

    if (app.selection.length == 0) {
        alert('Please make a selection and run script again.');

    } else if (!app.selection[0].parentStory.tables[0].isValid) {
        alert('No table found in selection.');

    } else {

        var _table = app.selection[0].parentStory.tables[0];
        var _rows = _table.rows;
        var alternator = 0;

        for (var i = 0; i < _rows.length; i++) {
            if (_rows[i].rowType === RowTypes.BODY_ROW) {
                if (_rows[i].cells.length == 1) {
                    // row is a subhead (all cells are merged into one)
                    setStyle(
                        app.activeDocument,
                        _rows[i].cells[0],
                        'cellStyle',
                        subheadStyleName,
                        true
                    );
                    // reset alternator flag
                    alternator = 0;
                } else {
                    // set body cell style according to alternator flag
                    setStyle(
                        app.activeDocument,
                        _rows[i].cells.everyItem(),
                        'cellStyle',
                        alternator == 1 ? styleName2 : styleName1,
                        true
                    );
                    // switch the alternator between 0 and 1
                    alternator = (alternator + 1) % 2;
                }
            }
        }
    }


    // just a convenience function for setting styles
    function setStyle(doc, item, styleType, styleName, clearOverrides) {
        if (doc == undefined || item == undefined || styleName == undefined) return;

        if (clearOverrides == undefined) clearOverrides = true;
        switch (styleType.toLowerCase()) {
            case 'cellstyle':
                if (doc.cellStyles.itemByName(styleName).isValid) {
                    item.appliedCellStyle = doc.cellStyles.itemByName(styleName);
                    if (clearOverrides) item.clearCellStyleOverrides(false);
                } else {
                    throw ('Cell Style "' + styleName + '" not found.');
                }
                break;
            case 'paragraphstyle':
                if (doc.paragraphStyles.itemByName(styleName).isValid) {
                    item.texts[0].paragraphs.everyItem().appliedParagraphStyle = doc.paragraphStyles.itemByName(styleName);
                    if (clearOverrides) item.texts[0].clearOverrides(OverrideType.ALL);
                } else {
                    throw ('Paragraph Style "' + styleName + '" not found.');
                }
                break;
            case 'characterstyle':
                if (doc.characterStyles.itemByName(styleName).isValid) {
                    item.texts[0].paragraphs.everyItem().appliedCharacterStyle = doc.characterStyles.itemByName(styleName);
                    if (clearOverrides) item.texts[0].clearOverrides(OverrideType.CHARACTER_ONLY);
                } else {
                    throw ('Character Style "' + styleName + '" not found.');
                }
                break;
            default:
                throw ('Unrecognised styleType "' + styleType + '".');
                break;
        }
    }
}

 

 

 Let me know if that works for you.

- Mark

 

Edit: the downside of this script is that it will apply the style to the entire row, so if you have different cell styles for different columns, it won't work, although with a bit of finesse it can be adjusted. One possibility is to change the "clearOverrides" flag on the setStyles function calls to false, but it will depend on how the table is set up whether this works. Or you could adjust the script to set each cell of each row specifically.

Likes

Translate

Translate

Report

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
Explorer ,
Jul 22, 2021 Jul 22, 2021

Copy link to clipboard

Copied

This.... is amazing. Perfect!

You've saved me hours of work and shown me again, the power of this community. Thanks so much, and thanks to Eugene too, as that article did have some interesting bits on there for me too.

Again, thanks so much!

Likes

Translate

Translate

Report

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
Enthusiast ,
Jul 22, 2021 Jul 22, 2021

Copy link to clipboard

Copied

LATEST

Nice!

Likes

Translate

Translate

Report

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