• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

Automatisation, supprimer des lignes vides dans un tableau automatiquement

Community Beginner ,
Sep 27, 2022 Sep 27, 2022

Copy link to clipboard

Copied

Bonjour,
Je cherche à automatiser certains process via InDesign. Après une fusion de données, je me retrouve avec des pages contenant des tableaux avec plusieurs lignes vides.
Savez-vous s'il est possible de supprimer automatiquement toutes les lignes vides de divers tableaux dans une maquette InDesign ? À ma connaissance, rien pour supprimer des lignes vides avec du GREP.
J'ai trouver ceci sur un forum mais je ne sais pas comment créer un script dans indesign, Merci pour votre aide

The following script should remove any empty rows in all tables in a document:

EDIT: From prior experience, I know it's a better idea to count backwards when deleting, so here is the earlier script with the order reversed:

 

var myDocument = app.activeDocument;

for(var i=myDocument.textFrames.length-1; i>=0; i--){

    for(var j=myDocument.textFrames.tables.length-1; j>=0; j--){

        for(var k=myDocument.textFrames.tables.rows.length-1; k>=0; k--){

            myContents = 0;

            for(var l=myDo

TOPICS
Feature request , Scripting

Views

148

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

Community Expert , Sep 27, 2022 Sep 27, 2022

Hi @Antony5EAF, here's a little script that should work on basic tables. Please let me know if it works in your case.

- Mark

 

 

function main() {


    // process all tables in active document
    removeEmptyTableRowsAndColumns(app.activeDocument);


    /**
     * Removes empty Rows and Columns from
     * all tables in a document, or a single
     * table.
     * @author m1b
     * @version 2022-09-27
     * @param {Document|Table} docOrTable - an Indesign Document or Table.
     */
    funct
...

Likes

Translate

Translate
Community Expert ,
Sep 27, 2022 Sep 27, 2022

Copy link to clipboard

Copied

Hi @Antony5EAF, here's a little script that should work on basic tables. Please let me know if it works in your case.

- Mark

 

 

function main() {


    // process all tables in active document
    removeEmptyTableRowsAndColumns(app.activeDocument);


    /**
     * Removes empty Rows and Columns from
     * all tables in a document, or a single
     * table.
     * @author m1b
     * @version 2022-09-27
     * @param {Document|Table} docOrTable - an Indesign Document or Table.
     */
    function removeEmptyTableRowsAndColumns(docOrTable) {

        if (docOrTable.constructor.name == 'Document') {

            // process all tables in the document

            var tables = docOrTable.stories.everyItem().tables.everyItem().getElements();

            for (var i = 0; i < tables.length; i++)
                removeEmptyTableRowsAndColumns(tables[i]);

            return;

        }

        if (docOrTable.constructor.name !== 'Table')
            return;

        var table = docOrTable,
        empty = /^\s*$/;

        // remove empty rows
        for (var r = table.rows.length - 1; r >= 0; r--)
            if (empty.test(table.rows[r].cells.everyItem().contents.join('')))
                table.rows[r].remove();

        // remove empty columns
        for (var c = table.columns.length - 1; c >= 0; c--)
        if (empty.test(table.columns[c].cells.everyItem().contents.join('')))
                table.columns[c].remove();

    };


} // end main

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Remove Empty Columns and Rows');

 

Edit: changed the test for emptiness to handle more cases.

 

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
Community Beginner ,
Sep 27, 2022 Sep 27, 2022

Copy link to clipboard

Copied

Bonjour m1b et merci pour votre réponse. Je n'ai jamais rentré de code dans InDesign et je ne sais pas comment faire. Pouvez-vous me dire comment entrer ce script dans indesign s'il vous plaît ? Merci beaucoup.

 

Hello m1b and thank you for your answer. I've never entered code into InDesign and I don't know how to do it. Can you tell me how to enter this script in indesign please? Thanks a lot.

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
Community Expert ,
Sep 27, 2022 Sep 27, 2022

Copy link to clipboard

Copied

Hi @Antony5EAF,  no problem. Here are the steps.


1. Select the text from my post - just the "code" styled part
2. Make a new text file in Notepad or TextEdit (must be plain text—not rich text)
3. Paste
4. Save as "Remove Empty Rows and Columns.js" (note: file extension is "js") to your desktop
5. In Indesign, open the Script panel, right-click on on User folder and choose "Reveal"
6. Move the file you saved in step 4 to the User folder that should now be visible.
7. Back in Indesign, the script should appear in the User folder of Scripts Panel (see Window menu > Utility)
8. Double click to run the script

 

Let me know if you get stuck.

- Mark

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
Community Beginner ,
Sep 27, 2022 Sep 27, 2022

Copy link to clipboard

Copied

Merci Mark,

Malheureusement, j'ai ce message qui s'affiche après avoir double-cliquer sur le script :

-----

Thanks Mark,

Unfortunately, I have this message that appears after double-clicking on the script:

JavaScript Erreur !

Numéro de l'erreur : 8
Chaîne de l'erreur: Syntax error

Moteur: main
Fichier: /Users/anto/Library/Preferences/Adobe lnDesign/ Version 17.0/fr_FR/Scripts/Scripts Panel/Supprimer les lignes et les colonnes vides.js
Ligne : 1
Source:{\rtfl \ansi\ansicpgl252\cocoartf2639
Texte incorrect: \

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
Community Expert ,
Sep 27, 2022 Sep 27, 2022

Copy link to clipboard

Copied

This error suggests that you saved the text as rich text in step 2. You must save as plain text.

- Mark

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
Community Beginner ,
Sep 28, 2022 Sep 28, 2022

Copy link to clipboard

Copied

Bonsoir,

Bizaremment, ça fonctionne avec Notepad mais pas avec TextEdit.

Merci encore.

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
Community Beginner ,
Sep 30, 2022 Sep 30, 2022

Copy link to clipboard

Copied

Hello,

Strangely, it works with Notepad but not with TextEdit.

However, I don't know why it doesn't work after a data merge in InDesign. Incomprehensible.
Cordially,

Antony

Bonjour,

Bizaremment, ça fonctionne avec Notepad mais pas avec TextEdit.

Par contre, je ne sais pas pourquoi ça ne fonctionne pas après une fusion de données dans InDesign. Incompréhensible.
Cordialement,

Antony

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
Community Beginner ,
Sep 30, 2022 Sep 30, 2022

Copy link to clipboard

Copied

Capture d’écran 2022-09-30 à 14.19.22.pngCapture d’écran 2022-09-30 à 14.20.02.png I found the problem: after the data merge, the empty lines contain ::# which seems to block the script. While removing the continuum from an empty line, only # remains when displaying the invisible characters. Do you know how to integrate this into the script please?
Thank you for your knowledge

 

J'ai trouvé le problème : après la fusion de donnée, les lignes vides contiennent ::# ce qui semble bloquer le script. Tandis qu'en supprimant le continu d'une ligne vide, il ne reste que # en affichant les caractères invisibles. Savez vous comment integrer ceci dans le script s'il vous plaît ?
Merci pour vos connaissances

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
Community Expert ,
Sep 30, 2022 Sep 30, 2022

Copy link to clipboard

Copied

Hi @Antony5EAF, yes that sounds like what is happening. The script only deletes a row/column if it is completely empty.

I can probably modify it to handle your case, but can you please post an example table that has the invisible characters?

-Mark

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
Community Beginner ,
Sep 30, 2022 Sep 30, 2022

Copy link to clipboard

Copied

Capture d’écran 2022-09-30 à 16.53.23.pngCapture d’écran 2022-09-30 à 16.53.15.png

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
Community Expert ,
Sep 30, 2022 Sep 30, 2022

Copy link to clipboard

Copied

Hi @Antony5EAF, I have updated the script above to use a better test for emptiness. Please try it out. If it still doesn't work, please post an Indesign sample file so I can test with that.

- Mark

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
Community Expert ,
Sep 30, 2022 Sep 30, 2022

Copy link to clipboard

Copied

LATEST
Strangely, it works with Notepad but not with TextEdit.

To save plain-text from TextEdit, go to the Format menu > Make Plain Text, and then save the document.

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
Community Beginner ,
Sep 27, 2022 Sep 27, 2022

Copy link to clipboard

Copied

Pour information, j'ai utilisé tout ceci dans mon fichier texte :

function main() {


// process all tables in active document
removeEmptyTableRowsAndColumns(app.activeDocument);


/**
* Removes empty Rows and Columns from
* all tables in a document, or a single
* table.
* @author m1b
* @version 2022-09-27
* @Param {Document|Table} docOrTable - an Indesign Document or Table.
*/
function removeEmptyTableRowsAndColumns(docOrTable) {

if (docOrTable.constructor.name == 'Document') {

// process all tables in the document

var tables = docOrTable.stories.everyItem().tables.everyItem().getElements();

for (var i = 0; i < tables.length; i++)
removeEmptyTableRowsAndColumns(tables[i]);

return;

}

if (docOrTable.constructor.name !== 'Table')
return;

var table = docOrTable;

// remove empty rows
for (var r = table.rows.length - 1; r >= 0; r--)
if (table.rows[r].cells.everyItem().contents.join('').length == 0)
table.rows[r].remove();

// remove empty columns
for (var c = table.columns.length - 1; c >= 0; c--)
if (table.columns[c].cells.everyItem().contents.join('').length == 0)
table.columns[c].remove();

};


} // end main

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Remove Empty Columns and Rows');

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