Help with a Table Script

Viewing 5 reply threads
  • Author
    Posts
    • #97891
      Kelli Fleck
      Member

      I am editing a table script I have. I have these two lines but I don’t know how exactly to modify it so it will do what I want.

      table.rows.everyItem().cells.everyItem().paragraphs.everyItem().appliedParagraphStyle = paragraphStyle(‘Table’, ‘Table – Body Text’); // Apply “Table – Body Text” to all text
      table.rows.everyItem().cells.everyItem().paragraphs.everyItem().appliedParagraphStyle = paragraphStyle(‘Table’, ‘Table – Body Number’); // Apply “Table – Body Numbers” to all numbers

      I want to apply the style “Table – Body Text” to cells that contain letters but may also contain numbers.
      I want to apply the style “Table – Body Numbers” to cells that contain ONLY numbers.

      Can anyone help me? Please. :)

      Kelli

    • #97894
      Mike Dean
      Member

      I think the easiest thing would be to leave the first line as is so it styles everything with the main body text style, then replace the second line with a GREP search that will find all number-only cells within that style and table.

      So the second line would be replaced with something like this:
      //create variables for paragraph styles
      var tableBodyStyle = paragraphStyle(‘Table’, ‘Table – Body Text’);
      var tableNumberStyle = paragraphStyle(‘Table’, ‘Table – Body Number’);

      //GREP to find text that only contains numbers, comma separator, or decimal, currency symbol
      app.findGrepPreferences.findWhat = “^[\\d,\\.\\$]+$”; //this can be reduced if you only need digits
      app.findGrepPreferences.appliedParagraphStyle = tableBodyStyle;
      app.changeGrepPreferences.appliedParagraphStyle = tableNumberStyle;

      //search within current table
      table.changeGrep();

    • #97901
      Kelli Fleck
      Member

      Thank you!! I will try this.

    • #97902
      Kelli Fleck
      Member

      So this script works and I can see the GREP in the FIND/CHANGE but it isn’t applying to all. I am missing a command line I think.

    • #97903
      Kelli Fleck
      Member

      Oh I see the command
      table.changeGrep();

      But my error says “table is undefined”

      Ill keep seeing if I can fix that. :)

    • #97904
      Kelli Fleck
      Member

      I GOT IT TO WORK! THANK YOU!!! :)

Viewing 5 reply threads
  • You must be logged in to reply to this topic.
>