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

Tags: InDesign

Similar Questions

  • Script will not apply the paragraph style

    Hello

    I'm new to scripting in InDesign (CS3), and I'm trying to understand why the scipt below does not apply a style in the following text file? :

    < ASCII-WIN >

    < ParaStyle: Heading 1 > who are we? < ParaStyle >:

    For ease of reading, I have shortend the text file to just two lines.

    The script that I use to open and to format the text file is:

    Create a new document.

    myDocument var = app.documents.add ();

    Set the units of measure and the origin of the rule.

    myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;

    myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points;

    myDocument.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;

    Get a reference to the first master spread.

    var myMasterSpread = myDocument.masterSpreads.item (0);

    Get a reference to preferences on the margins of the first page in the Master spread.

    var myMarginPreferences = myMasterSpread.pages.item (0) .marginPreferences;

    Now set up the page margins and columns.

    myMarginPreferences.left = 4;

    myMarginPreferences.top = 70;

    myMarginPreferences.right = 70;

    myMarginPreferences.bottom = 78;

    myMarginPreferences.columnCount = 2;

    myMarginPreferences.columnGutter = 14;

    The margins of page and columns for the right-hand page.

    var myMarginPreferences = myMasterSpread.pages.item (1) .marginPreferences;

    myMarginPreferences.left = 48;

    myMarginPreferences.top = 70;

    myMarginPreferences.right = 70;

    myMarginPreferences.bottom = 78;

    myMarginPreferences.columnCount = 3;

    myMarginPreferences.columnGutter = 14;

    Adding Master Page items

    var myMasterSpread = myDocument.masterSpreads.item (0);

    var myLeftPage = myMasterSpread.pages.item (0);

    var myRightPage = myMasterSpread.pages.item (1);

    var myLeftFooter = myLeftPage.textFrames.add ();

    myLeftFooter.geometricBounds = [70, 742, 728, 528];

    myLeftFooter.textFramePreferences.firstBaselineOffset = FirstBaseline.leadingOffset;

    myLeftFooter.contents = SpecialCharacters.autoPageNumber;

    myLeftFooter.parentStory.characters.item (0) .pointSize = 11;

    myLeftFooter.parentStory.characters.item (0) .leading = 14;

    var myRightFooter = myRightPage.textFrames.add ();

    myRightFooter.geometricBounds = [48, 742, 728, 542];

    myRightFooter.textFramePreferences.firstBaselineOffset = FirstBaseline.leadingOffset;

    myRightFooter.contents = SpecialCharacters.autoPageNumber;

    myRightFooter.parentStory.characters.item (0) .pointSize = 11;

    myRightFooter.parentStory.characters.item (0) .leading = 14;

    myRightFooter.parentStory.characters.item (0) .justification = Justification.rightAlign;

    Adding master text frames

    var myLeftPage = myMasterSpread.pages.item (0);

    var myRightPage = myMasterSpread.pages.item (1);

    var myLeftTextFrame = myLeftPage.textFrames.add ();

    myLeftTextFrame.geometricBounds = [70, 70, 714, 528];

    myLeftTextFrame.textFramePreferences.firstBaselineOffset = FirstBaseline.leadingOffset;

    myLeftTextFrame.textFramePreferences.textColumnCount = 3;

    myLeftTextFrame.textFramePreferences.textColumnGutter = 14;

    Add a label to make the image easier to find later.

    myLeftTextFrame.label = "BodyTextFrame";

    var myRightTextFrame = myRightPage.textFrames.add ();

    myRightTextFrame.geometricBounds = [70, 48, 714, 542];

    myRightTextFrame.textFramePreferences.firstBaselineOffset = FirstBaseline.leadingOffset;

    myRightTextFrame.textFramePreferences.textColumnCount = 3;

    myRightTextFrame.textFramePreferences.textColumnGutter = 14;

    Add a label to make the image easier to find later.

    myRightTextFrame.label = "BodyTextFrame";

    Link the two frames using the nextTextFrame property.

    myLeftTextFrame.nextTextFrame = myRightTextFrame;

    The substitution of Master Page points and adds text

    var myTextFrame = myDocument.masterSpreads.item (0).pages.item (1).textFrames.item (0) .override (myDocument.pag es.item (0));

    Add text by setting the contents of the insertion of a string.

    In JavaScript, "\r" is a return character.

    .silence myTextFrame.insertionPoints.item (0) = "dok\r";

    Adding and applying a paragraph Style

    var myParagraphStyle = myDocument.paragraphStyles.item ("title 1");

    try {}

    var myName = myParagraphStyle.name;

    }

    {} catch (MonErreur)

    //The style of paragraph don't have not exist, so create it.

    myParagraphStyle = myDocument.paragraphStyles.add ({name: 'Title 1'});

    }

    We need to create a color. Check if the color already exists.

    myColor var = myDocument.colors.item ("Green");

    try {}

    myName = myColor.name;

    }

    {} catch (MonErreur)

    //The color have not exist, so create it.

    myColor = myDocument.colors.add ({name: 'Green', model: ColorModel.process, colorValue:[100,0,100,0]});})

    }

    Now set the formatting of the paragraph style.

    myParagraphStyle.appliedFont = "Arial";

    myParagraphStyle.fontStyle = "Bold";

    myParagraphStyle.pointSize = 24;

    myParagraphStyle.spaceAfter = 24;

    myParagraphStyle.spaceBefore = 24;

    myParagraphStyle.fillColor = myDocument.colors.item ("Green");

    Apply the style to the paragraph.

    myDocument.pages.item (0).textFrames.item (0).paragraphs.item (0) .applyParagraphStyle (myParag raphStyle, true);

    You can also use:

    myDocument.pages.item (0).textFrames.item (0).paragraphs.item (0) .appliedParagraphStyle = //myParagraphStyle;

    Import a text file

    Display a standard dialog box open the file to select a text file.

    var monFichierTexte is File.openDialog ("choose a text file");.

    If you selected a text file, and if you didn't press Cancel,

    Place the file of text on the first insertion point after the title.

    If ((monFichierTexte! = "") & & (monFichierTexte!) (= null)) {}

    myTextFrame.insertionPoints.item(-1).place (myTextFile);

    }

    Place a graphic

    Display a standard dialog box open the file to select a graphic file.

    var myGraphicFile is File.openDialog ("choose a graphic file");.

    If you have selected a graphics file, and if you didn't press Cancel,

    Place the graphic file on the page.

    If ((myGraphicFile! = "") & & (myGraphicFile!) (= null)) {}

    var myGraphic = myDocument.pages.item (0) .place (myGraphicFile);

    //Since you can place multiple graphics at once, the place method

    //returns a table. For the graph you have placed, get the first

    //item in the table (beginning of JavaScript arrays with element 0).

    myGraphic = myGraphic [0];

    //Create a style object to apply to the graphic image.

    var myObjectStyle = myDocument.objectStyles.item("GraphicFrame");

    try {

    var myName = myObjectStyle.name;

    }

    catch (MonErreur) {}

    //The an object style have not exist, so create it.

    myObjectStyle = myDocument.objectStyles.add({name:"GraphicFrame"});)

    }

    myObjectStyle.enableStroke = true;

    myObjectStyle.strokeWeight = 3;

    myObjectStyle.strokeType = myDocument.strokeStyles.item("Solid");

    myObjectStyle.strokeColor = myDocument.colors.item("Green");

    //The frame containing the graphic is the parent of the graphic.

    myFrame var = myGraphic.parent;

    myFrame.applyObjectStyle (myObjectStyle, true);

    //Resize the frame to a specific size.

    myFrame.geometricBounds = [0,0,600,600];

    //Fit the graph in the image proportionally.

    myFrame.fit (FitOptions.proportionally);

    / / Next, mount the frame to the resized image.

    myFrame.fit (FitOptions.frameToContent);

    var myBounds = myFrame.geometricBounds;

    var myGraphicWidth = myBounds [3] - myBounds [1];

    //Move the graphic frame.

    var myPageWidth = myDocument.documentPreferences.pageWidth;

    var myTopMargin = myDocument.pages.item (0).marginPreferences.top;

    myFrame.move ([myPageWidth-myGraphicWidth, myTopMargin]);

    //Apply a wrap to the graphic frame.

    myFrame.textWrapPreferences.textWrapType = TextWrapTypes.boundingBoxTextWrap;

    myFrame.textWrapPreferences.textWrapOffset = [12, 24, 12, 24].

    }

    I hope someone can point me in the right direction.
    Thanks in advance.
    Ron

    Hey, Ron.

    The problem has nothing to do with your script. You can see if you attempt to place the file from indesign tagged text by hand.

    Your instinct for divide and conquer for debugging is a good - have a short text file to work with is very useful - of course this is also true for the script.

    During the validation of the scripts on the forum, please do not use the syntax insert > feature Java which lies behind the > arrow in the toolbar. Otherwise, cut and paste your script are difficult requiring manual corrections.

    Anyway, your problem is that each paragraph can have only a single paragraph style, and it's the last one that you define.

    So in your IDTT file, you set the heading 1 paragraph style, enter the content of the paragraph and then set the style of paragraph votes to zero.

    If you have included a line break before setting the style of paragraph votes to zero, you must set the None style for the following paragraph. But since you have not, it resets just the style to the current paragraph.

    In short: success back before .

  • retention of the words italic when you apply the paragraph style

    When you place text in InDesign, I want to apply a paragraph style, but keep some (foreign) words in italics without having to search for each word and apply the italic character style. Texts are long and not originated by myself.

    The most recommended book for beginners here on the forum is Visual QuickStart of Sandee Cohen for InDesign. The 'bible' in my opinion, for very advanced users is Real World InDesign.

  • ID CC 2015 crashes as soon as I (try to) apply the paragraph style to the text.

    I work on a Mac Pro (mid-2009), OS X 10.10.4, 16 GB of RAM

    Original hard drive is 1 TB (where applications are installed), second drive (designated as working drive, and where all the work files are housed) is 2 TB.

    Currently subscribe to Adobe CC 2015, using InDesign with last update

    I have been working for several days on a long paper (paper) and have developed 12 paragraph styles, using two fonts - Garamond first Pro and Helvetica Neue LT and the document has facing pages.

    Yesterday, my client (the author) has asked all text flow on the odd pages, for illustrations on all pages, so I did all the text boxes thread directly downward of pages on the right (odd pages).

    The first three chapters were style before I changed the threading of text box. Now, when I open the document and begin to apply styles to paragraph for the rest of the text (nine more chapters, which automatically adopted the style of main text as soon as I stuck in the newly-threaded text boxes), ID crashes when I highlighted a section of text and click a paragraph style.

    I checked the permissions and preferences. The only thing I can think is from the document from scratch.

    Any other suggestions?

    Thread the text boxes only on odd pages cause the problem, since it does not have facing pages?

    Thank you.

    There could be corruption in the document.

    Save the document with IDML and reopen the IDML in InDesign.

  • How to apply the paragraph style to all paragraphs

    Hi people,

    Simple question. New to JS script here (but so far love it).

    I am trying to apply a paragraph (myTextStyle) style to all paragraphs in a story.

    Right now, I set it up as follows:

    tabletDocument.pages.item (0).textFrames.item ("story").paragraphs.item (0) .applyParagraphSty (myTextStyle, true);

    Obviously, it's just the first paragraph - item (0)-, but no changes to the code it throws.

    Can I implement something to it or a beach (first to last), so it will apply to all of them?

    Thanks in advance!

    N

    Just set the property .appliedParagraphStyle on the whole story.

  • Apply the paragraph style instead of runned text simply by clicking on the text box

    I'm changing the style of the text entity. Is there another way to change it to select all the text, and then set the style?

    Capture.JPG

    IT is threaded text block (not a box!) you have to select all the blocks of text at a time in the thread (which is impossible if they are on different spreads) or you must select all of the text to apply a style.

    If the text block is not passed, you can select and apply the text.

    I do not see a problem to select all the text. Use the text tool, click in the text and the cmd/ctrl + A and apply the style. Not a problem, not a lot of work.

    A box is something like BleedBox, CropBox or something like that. Objects in InDesign are still frames or paths.

  • Apply the paragraph style to a glyph and not the glyph displayed?

    I have a large Word document I have to mark up with different paragraph styles. Fortunately the data contains different glyphs for specific text strings, and so I might have the styles of paragraph kick in when he meets the glyph. But ultimately, I need to remove the glyphs when I go to print, and therefore the style will be deleted also.

    I wonder if it is possible to change the glyph to some kind og hidden state. I could mess with the x position of the text string, but I'm not not to keen on this solution. Someone has an idea?

    You must use 'GREP', not 'text', in the Find/Replace window!

  • Selection of parts and columns, or entire lines and apply the character style

    I am trying to apply character styles to certain parts/whole rows and columns.

    I can change individual cells with the following code...

    table = app.selection[0];
    if (table.hasOwnProperty("baseline")) table = table.parent;
    if (table instanceof Cell) table = table.parent;
    if (table instanceof Column) table = table.parent;
    if (table instanceof Row) table = table.parent;
    if (table instanceof Table)
    
    {
     table.rows[0].cells[6].texts[0].appliedCharacterStyle = "none report";
     }
    

    ... but when I try to select an entire line, I get the error 'Object does not support property or method' texts. "" "When I try one of the following two codes.

    {
     table.rows[0].cells.texts.appliedCharacterStyle = "none report";
     }
    

    {
     table.rows[0].cells.appliedCharacterStyle = "none report";
     }
    

    Anyone know how I can do the following?

    1. Select any row (or column) and apply the character style

    2. Select the last line (regardless of the number of rows in the table) and apply the character style

    3. apply the character style to specific columns (with theexception of the cells of two albums)

    Thank you!

    Hello

    Change this line:

    table.columns[a].cells.itemByRange(2,-1).texts.everyItem().appliedCharacterStyle = "chart orange";
    

    for the first 2 rows in each column

    Jarek

  • Insert a blank space in the paragraph style?

    Is it possible to integrate a white space inserted (en character) in a paragraph style?

    I created a paragraph to chapter headings style. Chapter and number are centered horizontally on the page with a thick end line (key) on each side - a little like that, except that I use the dashboard to create the line in this example:

    -------------------------------------  Chapter 2  ------------------------------------

    Inserted white spaces before and after 'Chapter 2'.  However, when I try to apply the paragraph style to another title, the spaces are not there.

    (Line thin thickness was created as text underscore and the offset is vertically centered with the text.  It would make a difference if I created the thick end line in the form of a graph?)

    Oh and I also tried to create an object style, but it does not recognize spaces, either.  I know that something will work, but little by little learning has not met yet the solution.

    Thank you.

    Do it like this:

    1 make the high line a paragraph above net. Assign the 'Column' width (full) and set its vertical offset in right position.

    2. Add a paragraph below NET. Together, this upright even shifted, but makes a little (or a lot) more thick. Set its color [Book]. Set the width of 'Text', not 'column '. Then set the negative value of the width approx. white space you want on the left and right - something like 'mm-2' the left indent and right.

    3. you're done!

  • Is it possible to change the paragraph style (none)?

    Whenever I make a bulleted list or a numbered list, I get a syle of fonts that we don't use in our project.  I tried to change this style, but it is grayed out.  All other styles allow editing.  How can I change this default style (none)?  I did a search in the file help and on the forum but have not seen any results.  It's too simple or others are ok with this style.

    Thank you

    The choice is to apply other styles like I did, or simply to set your LI style, which is the way of pure HTML. The reason why I do that you cannot map the tag LI for printed documents. I have just started the list, select the style that I want and that's all. It is an extra step.

    What is behind this change is that people complained that the code should be clean and now it is the case, people are aware there is a down side.

    When no style is applied, as zero, the police will be what is defined by the browser. Try changing the default font in your browser for some obscure fonts and generates output. What you'll see is this obscure font. Now see the same output to another browser with a different default font.

    You may not modify any as Willam explained. None means that no style is applied so that applies the default value of the browser. You will see may not be in Arial, the next person may see as something else. Modify a CSS sets styles you include in this CSS. You apply the paragraph styles or you don't, as in no style is applied that in none.

    Clearer now?

    See www.grainge.org for creating tips and RoboHelp

    @petergrainge

  • 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")

  • Automatically apply "next paragraph Style...". "in place of the text

    I want to import an Excel (arrow) line 8 500 spreadsheet into InDesign and have it add the necessary number of pages and text related frameworks can flow text AND format her, lines spare in 1 2 paragraph styles. I can do everything until it automatically formatting the text. Paragraph Styles are set up for "Style of next paragraph...". "but it doesn't seem to work on the text. Can anyone help?

    I don't know if this can be done with a table, which is probably what you get from placing your excel file. A table Style might work.

    If you convert a table to text, however, you can select all, right-click on the name of the first style that you need in the paragraph styles Panel, and then choose apply and following style.

  • Table of contents, problems in applying the character style

    Hi all

    This is my first post, I checked if there was already something similar, but I can't find anything so I'm asking here.

    I work with Indesign 9.3 and I created a book of 80 pages and there are 20 + chapters.

    I wanted to create a table of contents, so I made an and I put my paragraph for her style, but I had problems to set the character style (he set only to the number of the page, but not to the number and the name of the chapter).

    When I create my summary style I have no problem to indicate the paragraph style that you want to use (and then it automatically applies it properly when I generate my list).

    The problem I want to solve, is that I need that my table of contents automatically the value of the character style, cause, for the moment, I have to apply it after its generation.

    Sorry for my bad English, I hope you understood

    Concerning

    Filippo

    In this case you must use the character for numers style nested within the paragraph style

    I'm usually two independent sparagraph styles (primary materials) chapters and sections (toc details). In this way, you can add a different same nested character style to stand them.

    Addibn later - style, it is not good idea. After the update of the table of contents, you have lost the

    macpawel

  • 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 the Master Page by using the paragraph Style

    Hi all

    I am a beginner in the script. Learn the script through tutorials cs3 scripts.

    According to the paragraph style it automatically applies the master page.

    For example:

    Paragraph style = "CT".      To apply the Master Page = 'A-Master '.

    Paragraph style = "PT";       To apply the Master Page = "B-Master".

    These are the lines I'm working on:

    myDocument var = app.activeDocument;

    var myPStyles = myDocument.paragraphStyles.everyItem () .getElements ();

    myPage var = myDocument.pages.everyItem () .getElements ();

    for (i = 0; i < myPStyles.length; i ++)

    {

    If (myPStyles [i] .appliedParagraphStyle is "CT")

    {

    .appliedMaster myPStyles [i] = 'A-master. "

    }

    }

    Where I have error. Can someone help me solve this problem.

    Thanks in advance engineering...

    Try this one,

    var myDocument = app.activeDocument;
    var myParas = myDocument.stories.everyItem().paragraphs.everyItem().getElements();
    var myPage = myDocument.pages;
    for(i=0; i
    

    Good luck...

Maybe you are looking for