Apply the table style based on the contents of the cell

I'm on a Mac, OS 10.8.5 using InDesign 5.

Does anyone know how to apply a table style based on the content of text found in a cell in javascript?

I need to find the document and change all the styles table 'LONG orange verbatim' If the text "HS:" appear in the header line.

I've been playing with scripts found with the following 3 wires, but can get it to apply a table style.

Thank you!

Apply Table Cell Style based on text search and How to apply a cell of table based on grep style search? and Re: find PStyle and apply the cell Style in the Table

Here are the corrected lines:

var curDoc = app.activeDocument;
var allTables = curDoc.stories.everyItem().tables.everyItem(); 

app.findTextPreferences = app.changeTextPreferences = null;
app.findTextPreferences.findWhat = "HS:";
var allFounds = allTables.findText();
app.findTextPreferences = app.changeTextPreferences = null;

for ( var i = 0; i < allFounds.length; i++ ) {
    var curFound = allFounds[i];
    if ( curFound.length == 1 ) {
        var curFoundParent = curFound[0].parent;
        if ( curFoundParent.parentRow.rowType == RowTypes.headerRow ) {
            curFoundParent.parent.appliedTableStyle = curDoc.tableStyles.itemByName( "verbatim orange LONG" );
        }
    }
}

Tags: InDesign

Similar Questions

  • Help with a script that detects the content in a cell and apply the cell style to line

    Hello


    I am trying to add an article to my table formatting script that is a cell with the word 'Budget' (but this can be written as ' Budget:' or ' Budget: (E) "- but without the speech marks) and apply the cell Style - SponsorCells - to all the cells of the whole line. I currently have on what it will, but it does not work:


    function checkWhichTable()
    {
    // ensure the user made a selection
    if (app.selection.length != 1)
    return null;
    var currentTable = app.selection[0];
    if (currentTable.hasOwnProperty("baseline"))
    {
    currentTable = app.selection[0].parent;
    }
    while (currentTable instanceof Cell || currentTable instanceof Row || currentTable instanceof Column)
    currentTable = currentTable.parent;
    if (!(currentTable instanceof Table))
    {
    // No table selected
    return null;
    }
    return currentTable;
    }
    app.doScript(checkUserSelection, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Process Table");
    
    
    function checkUserSelection ()
    {
    var a_table = checkWhichTable();
    if (a_table == null)
    {
    if (confirm("No table selected. Do you want to process *all* tables?") == false)
    return;
    allTables = app.activeDocument.stories.everyItem().tables.everyItem().getElements();
    for (aTable=0; aTable<allTables.length; aTable++)
    {
    processTable (allTables[aTable]);
    }
    } else
    {
    processTable (a_table);
    }
    }
    function processTable(table)
    {
    // do something here!
    
    
    //Set 1st Row Height
    table.rows[0].height = "30mm";
    
    
    //Find Text in Cell and apply Cell Style to Row 
    var  
      myCellText=['Budget', 'Budget:', 'Budget: (E)'];  
     var myRegEx = new RegExp("^("+myCellText.join("|")+")$");
      for (i=0; i<table.cells.length; i++)
      {
        if (table.cells[i].texts[0].contents.match(myRegEx))
          table.cell[i].appliedCellStyle = "SponsorCells";
      }
    
    
    //end - do something here!
    }  
    


    I can get the script to apply the cell style to "SponsorCells" for each cell that contain the word 'Budget' etc, but I need cell ever on this line to have the cell style applied. I tried to re-write line 56 which applies the style to a cell, but I can't seem to make it work. Any help would be great.


    Separate on this issue, I would like to have a line of code similar to the 46 line, which sets the 1st height of lines, but I would like to say "If a cell has 'A cell Style' and then applies the value height 10 mm". If someone could result as a help of bonuses, things would be great double.


    Thanks in advance!

    But that could be painfully slow. To speed things up, follow these steps:

    var cells = table.cells.everyItem().getElements();
    for (var i=0; i
    

    It is faster, because it creates an array of cells with a call to table.cells, which is several times faster than calling table.cells. And before assigning to line 12mm height is useful to check if it is already 12 mm. checking things in InDesign and do things only when it is necessary is much more effective than simply doing things even if they are not necessary.

  • Help with a script to search for text in a table cell and apply the cell style

    Hello

    I build the script which Jongware wrote in his post here http://indesignsecrets.com/tackling-tables-through-scripting.php - I am trying to create a variable in which I can add a number of different parts of the text, in this case it's different parts of the United Kingdom i.e. 'London', 'East', 'Scotland' etc. I just need the script to apply the cell Style - 'District Cell' - to any cell that contains text in the variable. Here's the script, if anyone can help I would be grateful.

    function checkWhichTable()
    {
    // ensure the user made a selection
    if (app.selection.length != 1)
    return null;
    var currentTable = app.selection[0];
    if (currentTable.hasOwnProperty("baseline"))
    {
    currentTable = app.selection[0].parent;
    }
    while (currentTable instanceof Cell || currentTable instanceof Row || currentTable instanceof Column)
    currentTable = currentTable.parent;
    if (!(currentTable instanceof Table))
    {
    // No table selected
    return null;
    }
    return currentTable;
    }
    app.doScript(checkUserSelection, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Process Table");
    
    
    function checkUserSelection ()
    {
    var a_table = checkWhichTable();
    if (a_table == null)
    {
    if (confirm("No table selected. Do you want to process *all* tables?") == false)
    return;
    allTables = app.activeDocument.stories.everyItem().tables.everyItem().getElements();
    for (aTable=0; aTable<allTables.length; aTable++)
    {
    processTable (allTables[aTable]);
    }
    } else
    {
    processTable (a_table);
    }
    }
    function processTable(table)
    {
    // do something here!
    
    
    //Find Text in Cell and apply Cell Style
    var textInCell=['London', 'Scotland', 'South West'];
    for (i=0; i<table.cells.length; i++)
    {
    if (table.cells[i].texts[0].contents==textInCell)
    table.cells[i].appliedCellStyle = "District Cell";
    }
    
    
    
    
    }
    

    Hello

    Change this feature:

    function processTable(table)
    {
    //Find Text (exactly as it is) in Cell and apply Cell Style
    var
      textInCell=['London', 'Scotland', 'South West'],
      mFound, cFound;
    
    app.findGrepPreferences = null;
    app.findGrepPreferences.findWhat = "^(" + cities.join("|") + ")$";
    mFound = table.findGrep();
    while( cFound = mFound.pop() )
      cFound.parent.appliedCellStyle = "District Cell";
    }
    

    Jarek

  • Apply a table style to all tables in the document

    I can't find a way to apply certain style of table for all tables in a document of p. 200.

    Specifically, clear any formatting within the cells (cell and replacements styles) would be a plus. All tables must have a unique look with a header cell style preset and style of cell in the body properly defined by a table style.

    All, even partial-help tips will be appreciated because they can save me time.

    I can't believe there is no way to do as other more complicated things are possible using find it & change don't function, for example objects, GREP, you name it.

    Roman

    This javascript will apply the table Style "tabs" to all the tables in the entire document and removes the replacements the (I'm not sure that this will happen automatically when you apply a table style). You set the header & body styles in the style of your table, and they should be applied automatically.

    for (s=0; s
    
    Copy, paste into a text editor (Notepad; TextEdit in plain text mode. best is the editor ESTK delivered installed with InDesign). Save as "ApplyTableStyles.jsx" in your own folder User Scripts, and it will appear in the Scripts panel. Double-click it to run it, and then sit down and relax.
  • How to apply an object style based on the paragraph style?

    Having a job where a single page with a frame of 3 columns is repeated many times.

    (He is always alone and behind a title page)

    But this system is not very good if the text follows... Formatting is lost.

    Of course, anchored frames should be a solution but I could prefer to apply a definition of the structure of text (just the 3 columns) with the f/change of menu:

    My page 3 columns that have a style always will be, this definition of the image.

    In anchored frames, insert a return to get on the next page is by default?

    Why you do not use * Span/Split columns * in your paragraph styles?

  • Script to apply the cell style after paragraph research

    Hello

    can someone help my make a script to search for all occurrences of a paragraph format in the tables and then apply a cell style to a document the bounding cell.

    Thanks in advance.

    Peter

    BTW Mac InDesign CS 6

    Hello

    Use this:

    var mDoc = app.activeDocument,
    pST = mDoc.paragraphStyles.item("paraStyleName"),
    cST = mDoc.cellStyles.item("cellStyleName"),
    mFound, mParent, count;
    
    app.findTextPreferences = null;
    app.findTextPreferences.appliedParagraphStyle = pST;
    mFound = mDoc.findText();
    count = mFound.length;
    while (count--) {
         mParent = mFound[count].parent;
         if (mParent.constructor.name == "Cell")
              mParent.appliedCellStyle = cST;
         }
    
    app.findTextPreferences = null;
    

    change paraStyleName and cellStyleName

    Jarek

  • A script to apply the style of cell to whole lines containing specific text

    Hello

    I use InDesign CC 2014

    Does anyone know how apply a cellstyle based on the content of text found in a cell in javascript?

    I need to find the document and change cell style in the entire line to 'cellStyle01' If the 'etc' text appears in the cell.

    I found a similar script here to the forum which apply the table style, but do not know how to change it to apply the cell style!

    var curDoc = app.activeDocument;
    var allTables = curDoc.stories.everyItem().tables.everyItem();
      
    app.findTextPreferences = app.changeTextPreferences = null;
    app.findTextPreferences.findWhat = "someText";
    var allFounds = allTables.findText();
    app.findTextPreferences = app.changeTextPreferences = null;
      
    for ( var i = 0; i < allFounds.length; i++ ) {
    var curFound = allFounds[i];
    if ( curFound.length == 1 ) {
    var curFoundParent = curFound[0].parent;  
    // curFoundParent.parent.appliedTableStyle = curDoc.tableStyles.itemByName( "tableStyle" );  
    curFoundParent.parent.appliedCellStyle = curDoc.cellStyles.itemByName("cellStyle01");  
    }
    }
    
    

    Thank you!

    Hello

    in this new case, you can't just change the last line, because yo I want to find not the entire table and lines and cells.

    Try this modified version:

    var curDoc = app.activeDocument;
    var allTables = curDoc.stories.everyItem().tables.everyItem(); 
    
    app.findTextPreferences = app.changeTextPreferences = null;
    app.findTextPreferences.findWhat = "some Text";
    var allFounds = allTables.findText();
    app.findTextPreferences = app.changeTextPreferences = null;
    
    for ( var i = 0; i < allFounds.length; i++ ) {
        var tableFound = allFounds[i];
        if ( tableFound.length > 0 ) {
            for ( var j = 0; j < tableFound.length; j++ ) {
                var curFound = tableFound[j];
                var cellsInRow = curFound.parent.parentRow.cells.everyItem();
                cellsInRow.appliedCellStyle = curDoc.cellStyles.itemByName( "cellStyle01" );
                cellsInRow.clearCellStyleOverrides( true );
            } // end for
        } // end if
    } // end for
    
  • Is it possible to adjust the height of the cell in a cell style?

    In the attached screenshot, the cell height is set to 0.125 exactly. I put my cursor in the cell, and then open the Panel styles of cell and created a new cell style based on the cell. But when I apply the cell style to other cells, it does not live up to cell. There are no substitutions or other styles are applied to other cells. I also opened the cell style definition in the Panel style of cell but don't see anywhere to set the cell height there either. Is there another way to do this that I'm missing?Screen Shot 2012-08-16 at 5.01.57 PM copy.jpg

    It is possible - and it's pretty simple.

    To set the height of row in the cell style, all you have to do is to use the insert of the cell above and below. As long as you set the style as "At least" then it works perfectly well for having predefined cell styles.

    I used it with success of large financial documents for a while without any hitches. For example, I use it to get the separation between the sections of the tables having a style with extra space above, and similarly for the totals at the bottom of the table lines. It can apply of course also different contour styles at the same time. Having the style defined as 'At least' also allows multiple line entries to still have the correct spacing above and below.

    So if you spend a little time of calculation required heights and to set up your styles, then apply a keyboard shortcut to each style, you can then save a lot of time during the formatting of the document.

    I just finished nearly 400 pages of financial tables using this method on the last two days!

    This solution may be suitable for your situation, but if you have a large number of tables to get through, he happened to be useful to give it a try.

  • Style of play based on the cell content

    Is it possible to use GREP or something to apply the style to its cells ' contents?

    Location:

    I have a table of about 10 K lines and in the cells of a column contain display symbols. They have different colors. Manually is a living hell for me.

    Use it (MyColorCellStyle should be set to your cell style):

    if (app.selection.length == 1)
    {
              app.findTextPreferences = null;
              app.findTextPreferences.findWhat = "<266a>";
              myResults = app.selection[0].findText();
              for (i=0; i
    

    Not bad, considering that I'm down with a case of the sniffles & me 'ead is' urting.

  • How to apply the Style to some words in a paragraph (or table)?

    I have a table with the #'s. Some numbers have a note marked with an asterisk.

    For example:

    A01-121600

    A01-121602

    A01-121608 *.

    A01-121610

    A01-121611 *.

    And in this table, there are hundreds of part # s with some with reference asterisks scattered through. I wish that the asterisks to be red in color and a smaller font size. So I created a character style to reflect that.

    So, my question is there a way to apply this new character Style to the entire table, then each asterisk is changed?

    Thank you.

    The find/replace field allows you to apply a character Style to all the text found.

    Another option: If all the text in your table is formatted with a paragraph Style, you could add a GREP style to add this character Style to all instances of an asterisk in the text of this paragraph Style. This way, if the new numbers of the asterisk was added later, the asterisk turns to Red style automatically.

  • Automatic table row apply the paragraph style

    Hello

    I am new to scripting in Indesign. I would like to write a script to apply a paragraph on a line style in a table like this:

    1 search for the string 'XX' in a table

    2. when the 'XX' string is found, apply a paragraph style named "ParA" to the line that contains the string "XX".

    3. apply a cell style named "CellA" to the cell that contains the sting "XX".

    4. apply the style of paragraph called 'Service' to the string "XX".

    5 search for the string "XX" to the end of the table

    Can someone help me?

    Hi Syd,

    For the selected table, use the below a.

    var doc = app.activeDocument,
        _tables = app.selection[0],
        i, j, k, l, a =0, _rows,_cells, rowlen; 
    
    _rows = _tables.rows;
    for(k =0;k<_rows.length;k++)
    {
        _cells = _rows[k].cells;
        for(l =0;l<_cells.length;l++)
        {
            if(_cells[l].contents == "xx")
            {
                rowlen = _cells[l].parent.cells.length;
                a = 0;
                while(rowlen--)
                {
                      _cells[l].parent.cells[a].paragraphs.everyItem().appliedParagraphStyle = doc.paragraphStyles.item("ParA");
                      a++;
                    }
                _cells[l].paragraphs.everyItem().appliedParagraphStyle = doc.paragraphStyles.item("ParB");
                _cells[l].appliedCellStyle = doc.cellStyles.item("CellA");
                }
            }
        }
    

    Kind regards

    Cognet

  • Apply a paragraph style to the first cell in the first row of a table

    I want to apply a paragraph style to the first cell in the first row of a table.

    I use JavaScript with ID CS 5.

    Thank you.

    . aragraphStyles.itemByName ("NameOfStyle") .p appliedParagraphStyle = app.activeDocument.paragraphStyleGroups.itemByName ("NameOfGroup")

  • How to apply the character style to table cell

    I'm sure it's basic, but I can't find any references on how to do it and my attempts have failed.  I use VB and CS5.5

    Basically what I'm trying to do is to select a table cell and apply a character like this style...

    MyCharacterStyle = myDocument.CharacterStyles.Add set

    myCharacterStyle.Name = "TH2".

    myTable2.Cells.Item (1) .appliedCharacterStyle = "TH2".

    with this code, I get a "object does not support this property or method.  myTable2.Cells.Item (...). appliedCharacterStyle ".

    I tried several other versions without success.

    Can someone tell me what would be the proper syntax to apply a character style to text in a table cell, or if it's still the right path to follow on that?

    I have to select the text in the cell rather than the cell itself, and if so, how do you do that?

    Thank you

    You do not need to select the text in the cell, but you need

    to target rather than the cell. It is true that in the user interface, you can

    Select the cell and apply a style of tank, but not with a script. Thus, in

    JavaScript is:

    myCell.texts.item (0) = .appliedCharacterStyle

    app.activeDocument.characterStyles.itemByName ("MyCharStyleName")

    It must be something similar in VB also.

    Of course, you can target the text in different ways:

    myCell.characters.everyItem () or myCell.paragraphs.everyItem () etc etc.

    but I think that the text is the most basic of the lot.

    Ariel

  • Unable to apply the class style to the line of the table?

    created a class style with pad of 10px on only right & vertical alignment at the top.

    I want to apply this class to a table row - but when I do - I get the correct vertical alignment - but none touch.

    If I apply the same class style to each td cell - then the alignment and buffer work.

    I have a stupid mistake? There are 40 cells of td in the rank - so it would be more quickly just to apply the class to the whole line. any ideas what I am doing wrong? much thanks in advance.

    And by the way, the best way to proceed would be next, using a
    descendant selector-

    .padThis td {vertical-align: top; padding: 10px ;}}

    ...


    Now, all thetags thatwill be filling and alignment
    you want.

    --
    Murray - ICQ 71997575
    Adobe Community Expert
    (If you * MUST * write me, don't don't LAUGH when you do!)
    ==================
    http://www.projectseven.com/go - DW FAQs, tutorials & resources
    http://www.dwfaq.com - DW FAQs, tutorials & resources
    ==================

    "dextre manika" wrote in message
    News:gnauf0$NKT$1@forums. Macromedia.com...
    > created a class style with pad of 10px side right only & vertical
    > alignment to
    > top.
    >
    > I want to apply this class to a table row - but when I do - I get correct
    > vertical alignment - but no key.
    >
    > If I apply the same style of class to each td cell - then the two alignment and
    > pad
    > work.
    >
    > I have a stupid mistake? There are 40 cells of td in the row - so he
    > would be more quickly just to apply the class to the whole line. any ideas what I am
    > making
    > evil? much thanks in advance.
    >

  • Turn off the cell table based on the contents of another cell

    Hello

    Using JDeveloper 12.1.2.3 and have a table where I want to disable a cell in the row, based on a value in another cell (in the same line) and vica versa, IE are mutually exclusive.

    The photo below shows the two cells that need to be mutually exclusive. I have implemented this by setting the "Disabled" field to something like that

    "#{row.bindings.LineOfBusiness.inputValue ne ""}"
    

    I also put the autosubmit = true and added a partial trigger for the other column cell.

    Should be simple enough, right.

    The problem is that it doesn't work and all lines is disabled.

    disablecell.png

    Any tips?

    It turns out that I needed to check on

    don't #{row.bindings.LineOfBusiness.inputValue ' 0'}

    for the selectOneChoice, then it worked.

Maybe you are looking for