Skip to main content
Liphou
Inspiring
July 3, 2018
Question

[JS] Changer la couleur d'un texte dans une cell

  • July 3, 2018
  • 1 reply
  • 1385 views

Bonjour,

Je cherche à modifier un de mes scripts pour mettre en couleur le texte d'une cellule (points d'insertion)  ou de plusieurs cellules sélectionner.

voici le script de départ actuellement il change la couleur de fond de la ou les cellules :

//$.writeln(app.selection[0].parent.constructor.name);

//$.writeln(app.selection[0].parent.fillTint);

       

    // app.selection[0].parent.fillTint = 25;

     if (app.selection[0].constructor.name === "InsertionPoint") {

       

            app.selection[0].parent.fillTint = 25;

        } else {

    

            app.selection[0].cells.everyItem().fillTint = 25;

     }

je dois utiliser la commende fillColor mais je bloc au niveau des parents.

Merci pour votre aide

Philou

This topic has been closed for replies.

1 reply

Liphou
LiphouAuthor
Inspiring
July 3, 2018

Ok pour une seul cellule

app.selection[0].parent.texts[0].fillColor = maCouleurs;

Liphou
LiphouAuthor
Inspiring
July 3, 2018

Voilà

cela devrait suffire :

//$.writeln(app.selection[0].parent.constructor.name);

//$.writeln(app.selection[0].parent.fillTint);

  

    if (app.selection[0].constructor.name === "InsertionPoint") {

       

          app.selection[0].parent.texts[0].fillColor = app.activeDocument.colors.item("Bleu Claire");

         

        } else {

    

       

              for (var i = 0; i < app.selection[0].cells.length; i++) {

                  app.selection[0].cells.texts[0].fillColor = app.activeDocument.colors.item("Bleu Claire");

                  }

             

     }

Si vous avez quelque chose de plus rapide ?

Merci à vous

Philou

Loic.Aigon
Legend
July 3, 2018

Hi Philou

var main = function() {

var doc = app.properties.activeDocument, sel, type, cell;

if ( !doc ) {

alert("You need an open document" );

return;

}

sel = app.selection;

if (!sel.length) {

alert("You need to select either a selection point, either some cells" );

return;

}

if ( sel.length == 1 ) {

sel = sel[0];

type = sel.constructor.name;

if ( type == "InsertionPoint" && sel.parent.constructor.name == "Cell" ) {

cell = sel.parent;

}

else if ( type=="Cell" ) {

cell = sel;

}

cell && cell.fillColor = getColor ( doc, "red",[0,100,100,0] );

}

}

function getColor ( doc, colorName, cmykArr ) {

var c = doc.colors.itemByName ( colorName );

!c.isValid && c = doc.colors.add( {

name:colorName,

colorValue:cmykArr,

model:ColorModel.process,

});

return c;

}

var u;

app.doScript ( "main()",u,u,UndoModes.ENTIRE_SCRIPT, "The Script" );

No loop implied