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

Need Table Script Help Please

New Here ,
Mar 16, 2015 Mar 16, 2015

Is there a script to distribute table columns evenly between guides or margins? Here is the issue I am having. I have a big catalog and I need to take the price column out of every item but then i have to (shift-Drag) the table to get it to fill the space where the price column was.

Thanks in advance for any help.

TOPICS
Scripting
516
Translate
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 ,
Mar 19, 2015 Mar 19, 2015

Hi,

1. To find the price column in a table

  •      Do you know the price column number? if yes, you can select table column based on column number.

              var table=app.activeDocument.stories.everyItem().tables.everyItem().getElements()

              var cells= table.columns[0].cells.everyItem().getElements(); // this will return array of cells from the column.

               //columns[0] -- replace your price column index

2. Fill Space where price column was.

  •      To change the cell content, first loop the cells and get cell content and replace with empty value.

               for(var i=0;i<cells.length;i++)

               {

                       cells.contents=" ";               

               }  

Hope this will help you

Regards,

Suneetha

Translate
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 ,
Mar 19, 2015 Mar 19, 2015

Hello. Thank you for your reply. I don't think i asked me question clearly so for that I apologize but I have mage an image to illustrate what I am trying to do.

1. This is that the table would look like before touching it

2. This is the table after taking out the price column which is always the last column in all of the tables

3. This is the table after evenly distributing the remaining column to fill the space where the price column was.

I have a script that does step 2, now I just need one that will do step 3 if possible? Basically I have a script that deletes the last column in every table in a document but I need one to distribute the columns after taking out the price one.

Thanks in advance for any help you can give me.

table_script.jpg

Translate
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 ,
Mar 19, 2015 Mar 19, 2015

If the table has to always cover the total width of the textframe, then this seems to be an easy enough task. Find the parent textframe width, divide it with the no. of columns of the tabs and then assign each column this new value of width.

A sample code is as follows

function main()

{

    var table = app.selection[0];       //This should be the table

    var textframe = table.parent;

    var noOfColumns = table.columns.length;

    var tfWidth = textframe.visibleBounds[3] - textframe.visibleBounds[1];

    table.columns.everyItem().width = tfWidth/noOfColumns;

}

main()

The precondition is that you select the table and then run the script. This should give you the idea and you can tweak the solution as needed.

Manan

Translate
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 ,
Mar 19, 2015 Mar 19, 2015

Thank you very much this works perfectly. Just one more question, is there code that can be added that will make the script run on every table in a document or do I have to select every table individually?

Thanks

Translate
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 ,
Mar 19, 2015 Mar 19, 2015
LATEST

I have tweaked the code a bit, this should work for you

function main()

{

    var table;

    var noOfStories = app.activeDocument.stories.length;       //Count of all the stories in the active document

    for(var j = 0 ; j < noOfStories ; j++)

    {

        var noOfTable = app.activeDocument.stories.tables.length;     //Count of all the tables within this story

        for(var i = 0 ; i < noOfTable; i++)

        {

            table = app.activeDocument.stories.tables;

            var textframe = table.parent;

            var noOfColumns = table.columns.length;

            var tfWidth = textframe.visibleBounds[3] - textframe.visibleBounds[1];

            table.columns.everyItem().width = tfWidth/noOfColumns;

        }

    }

}

main()

Translate
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