• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Table and cell Style

Community Beginner ,
Oct 12, 2011 Oct 12, 2011

Copy link to clipboard

Copied

Dear all,

Greetings....

The below script is working perfectly in indesign CS3 to apply the table and cell style. But in indesign CS4 is showing runtime error. Kindly help me on this........

var myTable = app.activeDocument.stories.everyItem().tables;

for (var n=0; n < myTable.length; n++)

{

     myTable.appliedTableStyle = "Table Style 1";

     myTable.cells.everyItem().appliedCellStyle = app.activeDocument.cellStyles.item("[None]");

     myTable.cells.everyItem().clearCellStyleOverrides (true);

     alert(myTable.rows.length);

    for (var a = 1; a < myTable.rows.length - 2; ++a)

     {

           myTable.rows.cells.everyItem().appliedCellStyle = "T body";

           alert(a);

     }

 

    myTable.rows[0].cells.everyItem().appliedCellStyle = "T col hd";//First Row

     myTable.rows[-1].cells.everyItem().appliedCellStyle = "T body bot";//Last Row

}

Thanks

Karthik

TOPICS
Scripting

Views

5.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Oct 13, 2011 Oct 13, 2011

Hi Karthik,

Please try the below JS Code and revert.

var myTable = app.activeDocument.stories.everyItem().tables;

for (var n=0; n < myTable.length; n++){

//~      myTable.appliedTableStyle = "Table Style 1";

//~      myTable.cells.everyItem().appliedCellStyle = app.activeDocument.cellStyles.item("[None]");

//~      myTable.cells.everyItem().clearCellStyleOverrides (true);

// Please check the table cell styles name is correct or not?

    var myActiveTable = myTable;

    myActiveTable.rows.itemByRange

...

Votes

Translate

Translate
Advocate ,
Oct 13, 2011 Oct 13, 2011

Copy link to clipboard

Copied

Hi M Karthik,

Your code  JS code is working perfecet on InDesign CS4 platform Mac OS 10.5.6. Can you please post the runtime error snapshot. And also can you do this please clear/delete the InDesign Preferences after that try again once.

thx

csm_phil

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 13, 2011 Oct 13, 2011

Copy link to clipboard

Copied

Hi

I am working on Windox XP CS4. As instructed, i have placed the runtime error screenshot image for yours reference....

script_error.JPG

Thanks

Karthik

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 13, 2011 Oct 13, 2011

Copy link to clipboard

Copied

can't help you with the script you have, but have seen an alternative script which may help. written by martin fischer. go to:

http://indesign.hilfdirselbst.ch/tabellen/allen-tabellen-eines-dokuments-ein-tabellenformat-zuweisen...

If the answer wasn't in my post, perhaps it might be on my blog at colecandoo!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 31, 2012 Jan 31, 2012

Copy link to clipboard

Copied

Is this for CS4 only? I try in CS5 (win7) and get nothing but errors.

i just want to apply a style over rides and a simple table styles to all my tables, but i can't find anything that works.  PLEASE HELP.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 31, 2012 Jan 31, 2012

Copy link to clipboard

Copied

If you don't tell us what the errors are, we cannot help you.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 01, 2012 Feb 01, 2012

Copy link to clipboard

Copied

You must attach screenshots using the web interface, you cannot do so via email.

You should probably go to the web site and edit your posts, they are inscrutable, and also contain extraneous quoted information from the previous posts.

There's not enough information about your problem to help you.

It sounds like it is detailed enough to merit a thread of its own.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 01, 2012 Feb 01, 2012

Copy link to clipboard

Copied

Hi John,

I'm at a loss as to how come the script works on one system but not mine(CS5 win7).

What are the coloured letters near the end of each of the last 3 lines of code?

What are the variables that I need to load with my table style name?

thanks

FYi, i've begun the brutal task of manual formatting, the deadline is looming.

Table_and_cell_Style-error.gif

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 01, 2012 Feb 01, 2012

Copy link to clipboard

Copied

Robert:

  Your error message refers to a string on line 2, "RB_Base_Table.length", which does not appear on line 2 of any of the versions of the script in this thread. Instead they have "myTable." Did you alter the script?

If so, why did you do so? As written, it operates on all tables in the document.

The colored letters are syntax highlighting intended to make it easier to read and understand the script. You can ignore the colors and simply cut and paste thes script verbatim.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 01, 2012 Feb 01, 2012

Copy link to clipboard

Copied

This came up when i ran the unaltered scipt on a 1 page doc (CS5 win7) containing a 3 col by 7 row table.

Table_and_cell_Style-error-Unchanged script.gif

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 01, 2012 Feb 01, 2012

Copy link to clipboard

Copied

I'm not sure what you're expecting. Line 9 of the script sets the style of some rows to a style named "TB."

I'm sorry for saying that the script needed to run unaltered. Clearly that's not the case. You do need to change the styles that the script uses (in double-quoted strings) into styles that are applicable to your situation. Even then the script is a bit specific...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 01, 2012 Feb 01, 2012

Copy link to clipboard

Copied

FANTASTIC, thank you John, the cell style now applies.

what xyntax should i use for appling a table style?

thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 02, 2012 Feb 02, 2012

Copy link to clipboard

Copied

what syntax should i use for appling a table style?

myActiveTable.appliedTableStyle="Whatever";

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 02, 2012 Feb 02, 2012

Copy link to clipboard

Copied

Thanks John,

I found a sample that sort of works;

myTable.appliedTableStyle = "RB_Base_Table";

What does the mean?

My latest issue is that cell and table styles over-rides need to also be applied in this script.

Though I'm half through my current 'table fest' project, it still behooves me to run a good script to finish the second half of my book in a fraction of the time that the first half took. Hopefully a good script will also alow me to have the weekend off after week of 10 and 12 hour daze.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 02, 2012 Feb 02, 2012

Copy link to clipboard

Copied

myTable.appliedTableStyle = "RB_Base_Table";

What does the mean?

It refers to the nth table, where n is a variable. Because it is a for loop, its contents execute once for every table.

In this case, "myTable" is the same as "myActiveTable," because of the assignment that makes that so.

My latest issue is that cell and table styles over-rides need to also be applied in this script.

It is not clear what you are asking for, if anything.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 02, 2012 Feb 02, 2012

Copy link to clipboard

Copied

Thanks John,

sorry about the ambigiuity of my request.

What I need is the syntax to clear overrides for paragraphs, cell and table styles, Please.

thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 02, 2012 Feb 02, 2012

Copy link to clipboard

Copied

Have you looked through the documentation, or the object model at http://jongware.mit.edu, or searched on the scripting forum for "clear overrides"?

It's really expected that you put a bit of effort into figuring this out yourself.

For a table, you can use myActiveTable.clearTableStyleOverrides();.

For cells, similarly, instead of (or in addition) to setting .appliedCellStyle, you can also call .clearCellOverrides().

For paragraph styles, it's a bit more complicated since you don't deal with paragraph attributes anywhere.

I suppose you can likely use cells.everyItem().paragraphs.everyItem().clearOverrides().

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 02, 2012 Feb 02, 2012

Copy link to clipboard

Copied

LATEST

Thank-you John,

And yes, initially, i did put a lot effort into it.

However, debugging the scripts that i did find was eating away at my production time, which was totally stressing out my manager.

I’m sorry for the bother that i’ve caused you, but your efforts have been tremendously appreciated!

Once again, thank-you John.

Robert Bourassa

Senior Production Artist

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 13, 2011 Oct 13, 2011

Copy link to clipboard

Copied

Hi Karthik,

Please try the below JS Code and revert.

var myTable = app.activeDocument.stories.everyItem().tables;

for (var n=0; n < myTable.length; n++){

//~      myTable.appliedTableStyle = "Table Style 1";

//~      myTable.cells.everyItem().appliedCellStyle = app.activeDocument.cellStyles.item("[None]");

//~      myTable.cells.everyItem().clearCellStyleOverrides (true);

// Please check the table cell styles name is correct or not?

    var myActiveTable = myTable;

    myActiveTable.rows.itemByRange(0,-2).cells.everyItem().appliedCellStyle = "TB";

    myActiveTable.rows[0].cells.everyItem().appliedCellStyle = "TCH";//First Row

   myActiveTable.rows.itemByRange(-2,-1).cells.everyItem().appliedCellStyle = "TBB";//Last Row

    }

Picture 1.png

the above js code output is like this snapshot.

thx

csm_phil

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 14, 2011 Oct 14, 2011

Copy link to clipboard

Copied

Thanks csm_phil. you have done a great job for me. Thanks a lot..................

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines