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

Tags: InDesign

Similar Questions

  • Script to search for text and remove the hyperlink and characterstyle link which applies (back to normal)

    I need help with my script to search for text and remove the hyperlink and characterstyle link which applies (returns the normal text).

    I can't do either as I want.  I want the user to be able to type in a dialog text they want to search for, do search this text IGNORING case (case insensitive) and then for all instances that he find it, remove character styles that are applied to the (set to [none]) and delete the hyperlinks.

    My code seems to define the character style [None], when I click on the text and look at the window of character Styles, BUT all old styles (font color, underline) are always applied and removed not as I want.

    Also, I can't understand how to remove all of the old links.

    Here is my code:

    myDocument var = app.activeDocument;

    var noneStyle = myDocument.characterStyles.item ("[None]");

    var myFindVal = "";

    var myErrorText = "";

    var myErrorCount = 0;

    myDialog = app.dialogs.add var ({name: "search user submitted text and delete hyperlinks from objects found.", canCancel: true});

    {with (MyDialog)}

    {with (dialogColumns.Add ())}

    {with (borderPanels.Add ())}

    staticTexts.add ({staticLabel: "search and delete hyperlinks for :"}); "})

    myTextBox var = textEditboxes.add({minWidth:100});)

    }

    }

    }

    If (myDialog.show () == true) {}

    myFindVal = myTextBox.editContents;

    doSearchAndReplace();

    app.findTextPreferences = NothingEnum.nothing;

    app.changeTextPreferences = NothingEnum.nothing;

    If (myErrorCount == 0) {}

    Alert ("done! ("Part of the links have been removed for: '" + myFindVal + ""! "");

    }

    else {}

    Alert ("last error: '" + myErrorText + "' & number of errors:" + myErrorCount);

    }

    }

    myDialog.destroy ();

    function doSearchAndReplace() {}

    app.findTextPreferences.findWhat = myFindVal;

    app.findChangeTextOptions.caseSensitive = false;

    app.findChangeTextOptions.includeFootnotes = false;

    app.findChangeTextOptions.includeHiddenLayers = false;

    app.findChangeTextOptions.includeLockedLayersForFind = false;

    app.findChangeTextOptions.includeLockedStoriesForFind = false;

    app.findChangeTextOptions.includeMasterPages = false;

    app.findChangeTextOptions.wholeWord = false;

    var myFoundItems = myDocument.findText ();

    for (i = 0; i < myFoundItems.length; i ++) {}

    myRemoveHyperlinkAndStyle (myFoundItems [i]);

    }

    }

    function myRemoveHyperlinkAndStyle (myFoundItem) {}

    try {}

    myDocument.hyperlinkTextDestinations.item (myFoundItem) .remove ();

    myDocument.hyperlinkTextSources.item (myFoundItem) .remove ();

    myDocument.hyperlinkURLDestinations.item (myFoundItem) .remove ();

    myFoundItem.applyCharacterStyle (noneStyle);

    }

    {catch (MyError)}

    myErrorCount ++;

    myErrorText = MonErreur;

    }

    }

    Hello

    Right, some hyperlink might be a pageItem...

    expand the 'if' condition with:

    If (myHyp [len].source.hasOwnProperty ("sourceText") &... content ==...)

    Jarek

  • We can search for text in a table?

    Hi people,
    I need to search for a text within a table.for ex, I need to find a word "ABEL" in a table.but I n don't know real field names in a table.without using DESC I should look for a string.that is that I should get the names of columns to runtime.for ex,'select * from emp where column_name as
    'ABEL % %';
    Here, this column_name value should be replaced by a select another statement.is it possible? can u suggest me? using oracle 9i.

    Concerning
    VIDS

    If it's just for a table, probably quite simply, I would opt for something like

    SQL> col search_word form a25
    SQL> col column_name form a25
    SQL> col text form a25
    
    SQL> var search_word varchar2(50)
    
    SQL> exec :search_word := 'al'
    PL/SQL procedure successfully completed.
    
    SQL> select  t.column_value.getrootelement() column_name,
            :search_word search_word,
            extractvalue(column_value, '*/text()') text
      from  table(xmlsequence(xmltype (
                                  cursor (select   * from dept)
                               ).extract ('ROWSET/ROW/*'))) t
     where lower(extractvalue(column_value,'*/text()')) like '%' || lower(:search_word) ||'%'
    /
    COLUMN_NAME               SEARCH_WORD               TEXT
    ------------------------- ------------------------- -------------------------
    LOC                       al                        DALLAS
    DNAME                     al                        SALES                    
    
    2 rows selected.
    
  • Is it possible to add text to the cells and apply the character style in the cell

    I work in InDesign on Mac 5.

    I have two tables of formatting with information that will be eventually combined. I implemented the scripts I found on these forums to add the columns needed, merge lines and fill the cells merged with the appropriate color, but can't two remaining tasks.

    1. is it possible to add text to a cell of some?

    2 and it is possible to apply a character style to cells? (different cells than those that I need to add some text)

    I played with this code but do not know if it is even close...

    {

    table. Rows [0]. Cells [0]. InsertText (' CS/PS");

    }

    {

    table. Rows [0]. Cells [0] .appliedCharacterStyle ("bold");

    }

    Here are the scripts that I have combined so far for the table...

    Add column

    myTable = app.selection [0];

    MyColumn = myTable.columns [1];

    for (a = 0; < 1; a ++)

    {

    myTable.columns.add (LocationOptions.AFTER, myColumn);

    }

    Merge lines

    table = app.selection [0];

    If (table.hasOwnProperty ("baseline") table) = table.parent;

    If (instanceof cell table) table = table.parent;

    If (instanceof column table) table = table.parent;

    If (instanceof row table) table = table.parent;

    If (instanceof Table table)

    {

    table. Rows [0]. Cells [0]. Merge (table.rows [0] .cells [1]);

    }

    {

    colours alternating in merged lines

    r = table.rows [1];

    n = app.activeDocument.swatches.item ("orange");

    b = app.activeDocument.swatches.item ("PANTONE 3005 C");

    for (c = 0; c < r.cells.length; c ++)

    {

    If (c & 1)

    r.Cells [c]. Properties = {fillColor:b};

    on the other

    r.Cells [c]. FillColor = n;

    }

    }

    Hello

    1. If you want to add the text, go further in:

    table. Rows [0]. Cells [0] .insertionPoints [0] .silence = ' CS/PS;

    2 similar with application of styles:

    table. Rows [0]. Cells [0] .texts [0] .appliedCharacterStyle = "bold" / / If this style is present in your doc

    Jarek

  • Is it possible to search for text in an Illustrator file from an external source like the Finder (Mac)?

    I'm trying to find some similar text strings on hundreds of files.  Specifically, I'm looking for dimensions.  4.50 "for example.  I want to see how many files have this dimension within them so that I can group them for production purposes.

    Is there a way to search for text in Illustrator (I use CS5) files from Finder?  Or another program of research?  I use a Mac.

    Any help would be GREATLY appreciated and would help save me a lot of time.

    Yes. While the Finder cannot find the content of .ai files, it can do it with .pdf files. If you change the extension of a .ai in .pdf file, you can use Spotlight to search by content.

    This fact, combined with a file rename utility as A Better Finder Rename, you can leave temporarily rename all of your .ai files so they end up in something like 'RENAMED.pdf '. Then, once you have performed your search, find all files ending in RENAMED.pdf, to delete the word "RENAMED" and change the end for .ai again.

    Of course, this isn't something you want to get into the habit of doing.

  • 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.

  • Need help with a script (o - o8) *, see the Virgin if there is no

    Hi all what I need help with a script I can't find an example.

    I'm trying to subtract 2 numbers and then multiply this product. (o o8) * one but I just want to do the calculations if all fields have the numbers IE field o, o8 of field and field one.

    Thank you in advance. I was stuck on this days searching the Internet.

    Assuming you want to affect the outcome of this calculation in another text field, use this code as a custom field calculation script:

    var o = this.getField("o").valueAsString;
    var o8 = this.getField("o8").valueAsString;
    var a = this.getField("a").valueAsString;
    if (o!="" && o8!="" && a!="") event.value = (Number(o)-Number(o8))*Number(a);
    else event.value = "";
    
  • Search for text when I start typing, I want to turn it off but it doesn'

    I discuss in shows from time to time and I find it annoying when every time I start typing the computer begins to search for text. I went to the options of firefox and it is not enabled but search for it. Can you suggest a way I can stop this from happening?

    Thank you

    Sherrie

    See:

  • Search for text in the option in Windows Search 4.0 Preview pane doesn't work do not

    I use XP SP3.  I recently downloaded Windows Search 4.0.

    When the Windows search results window opens, I noticed that it is possible to search for text in the preview pane.  I click on a file and go to OPTIONS > COMPONENT of VISUALIZATION, but see that FIND is grayed out and unavailable.

    This function worked before, when I loaded Windows Search first; now, it no longer works.  My files have been fully indexed; and I made no changes to the computer since then.  I tried to restart the computer, but there was no change.

    Any ideas? Matthew W. I. Dunn

    Hello Matthew w. I. Dunn, welcome.

    I recommend trying a system restore to see if that solves the problem. Try this:
    1. click on START
    2. click on "all programs".
    3. click on "Accessories".
    4. click on "system tools."
    5. click on "system restore."
    6 follow the prompts shown to restore your system to a date before the problem started. Although the system restore does not target the personal data, it is recommended that you back up all data such as music, photos and documents in case something is not bad.
    Let us know what happens
    Thank you!

    Ryan Thieman
    Microsoft Answers Support Engineer
    Visit our Microsoft answers feedback Forum and let us know what you think.

  • When searching for files in Windows Explorer (WIN 7), can the railways under folder reading "c:\help\me\please" instead of "Please (c:\help\me)?

    When searching for files in Windows Explorer (WIN 7), can the railways under folder reading "c:\help\me\please" instead of "Please (c:\help\me)?

    Thank you!

    What you can do is to do a search, right-click on any column heading (for example name, folder, etc.), and then click "Folder path" from the list that appears.  You can also click to turn off the folder.  The next time you're looking for in this area, this column of path of the folder should appear.  You can drag the columns in a different order also.

  • Search for text on a Web page in ModernUI IE10

    Is there a way to search for text on a Web page in the version of the modern UI for IE10?

    If you use modern IE, the shortcut must be identical to it in most web browsers:

    CTRL + F
    So, open IE, select a text field that opens the keyboard on the screen, then tap on and hold down the Ctrl key and press F release both. You should see a little extra box we pop that is your field of research to this page.
    Gives you what you're looking for?
  • Python script to search for users who belong to a group of weblogic

    Hello

    We know

    Python script to search for users who belong to a particular group in weblogic

    That's what I showed you already. You just need to add the function connect() and disconnect() around it and evaluate the slider that went back.

    If you don't want to learn how to write your own script and that you just want to use an existing one, try this one Weblogic Scripting Tool 101: WLST list users, groups, and users in groups

  • How to search for text in all of the PDF files on a mobile device?

    How to search for text in all of the PDF files on a mobile device?

    Not possible on mobile devices.

  • Can I search for text in iframe?

    I do an exploration to see if I can display content SharePoint in IFrames. Success! I can view Word files saved as HTML pages and view it in IFrames.

    But then, I decided to see if I can identify keyboards in the IFrame to a search. Alas, my plan falls flat.

    I suspect that the answer is no, but I hope to be denied. Can I somehow search for text that appears in an IFrame?

    Hello

    The IFrame points to something included in the RoboHelp project or he is simply presenting something from outside the project?

    If the content within the IFrame is part of the project, research should be able to find terms in the document. But I think that if he says something of that RoboHelp don't is not yet aware, you would see questions.

    See you soon... Rick

  • Search for characters, nested and apply the Cstyle

    I have

    you want to find the nested applied characters and apply the Cstyle, but my capture of code all the text in a document. Can you please guide me,

    nestedreport();

    function nestedreport() {}

    myDoc var = app.activeDocument;

    var myDocPath = myDoc.filePath;

    var myDocName = myDoc.name;

    try {}

    app.findGrepPreferences = app.changeTextPreferences = null;

    app.findGrepPreferences.findWhat = "^.» + » ;

    myFind = myDoc.findGrep (false);

    var ntexts = new Array;

    for (i = myFind.length - 1; i > = 0; i--)

    {

    if(myFind[i].contents.nestedStyles==null)

    {

    ntexts.push (myFind [i]. Happy)

    ntexts.appliedCharacterStyle = "Nested";

    }

    }

    }

    {catch (e)}

    }

    Screen shot 2015-07-21 at 2.26.33 PM.png

    Hello

    I'm still somewhat struggled with the final goal, however to make a small step:

    To detect a string that is formatted using nestedStyle (part of the content of the paragraph), you can use this:

    assuming that ==> text is selected - say a paragraph

    var
      cCharStyle,
      charStyles = app.selection[0].characters.everyItem().appliedNestedStyles,
      step = charStyles.length,
      resString = "";
    
      while ( (cCharStyle = charStyles.pop() ) && step--)
           if ( cCharStyle.length )
                resString = app.selection[0].characters[step].contents + resString;
    
    alert ( resString );
    

    Jarek

Maybe you are looking for

  • Firefox can not run a spoiler swap function in the forums

    HelloThis forum of http://www.overclock.net/t/1384767/official-the-korean-pls-monitor-club-qnix-x-star, there is a toggle spoiler list, for example 'FAQ', 'monitor Specs... "Basically I can't see the content of each wing by clicking on "+" or "click

  • store the resource name of visa in variable teststand

    Hello can I store a VISA resource name in a variable of teststand using the property api set of labview? If Yes, then I know how? concerning Giri-

  • FAILURE TO INSTALL UPDATES FOR VISTA ERROR - MS SERVICE PACK 4 - 663

    I'M USING THE VISTA OPERATING SYSTEM - CAN NOT INSTALL MICROSOFT SUITE SERVICE PACK4 - ONLY GIVE 663 ERROR MESSAGE - THE PROBLEM WAS APPEARING FOR ABOUT A MONTH NOW AND HAS DETERIATED THE COMPUTER PERFORMANCE - A TI BOTHERS ME A LOT

  • LaserJet M1212nf MFP: Error 22 scanner on LaserJet M1212nf MFP

    Hi all! I just got this error message after you copy a page. The error message remains after the reset of the printer. I ran the soft stop, turn on. I did not unplug the power cord while the unit is operating to avoid greater damage. Can I receive in

  • Switch Windows 10 to XP?

    I have a laptop Inspiron 5558 almost nine current to run Windows 10. W10 * big time and not is not compatible with my older version of Autocad and Photoshop software and update the software would cost more than the computer. I have a spare drive XP f