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

Add New Column to existing table

Contributor ,
Aug 22, 2022 Aug 22, 2022

Copy link to clipboard

Copied

Hi Everyone,

 

I'm trying to add new column with the existing table but causing an error.

What to do to add extra column to existing table.

 

Code I have done

 

 

IterateDocument();

function IterateDocument()
{
	for(myCounter = 0; myCounter < app.activeDocument.activeLayer.textFrames.length; myCounter++)
	{
         myStory = app.activeDocument.activeLayer.textFrames.item(myCounter);
		FitPageItem (myStory);
	}

	for(myCounter = 0; myCounter < app.activeDocument.activeLayer.rectangles.length; myCounter++)
	{
	    myStory = app.activeDocument.activeLayer.rectangles.item(myCounter);
		FitPageItem (myStory);
	}

}

function FitPageItem (mySel)
{
    //alert (mySel);
     var tableFitoption = "true";
    if(tableFitoption=="true")
    {
        AddColumnToTable (mySel);
     }
}

function AddColumnToTable (mySel)
{
    mySel.recompose();
    for (var j = 0; j < mySel.tables.length ; j++) 
    {
        var table = mySel.tables[j];
        alert(table);
        var columnlength = mySel.tables[j].columns.length;
        alert(columnlength);
        var rowlength = mySel.tables[j].rows.length;
        alert(rowlength);
        var rowValue = mySel.tables[j].columns[0].contents;
        alert(rowValue);
        var myTable = mySel.tables[j].add({columnCount:1,bodyRowCount:rowValue}); 
     }
}

 

  

-Jothi

TOPICS
Feature request , How to , Scripting

Views

131

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

Community Expert , Aug 23, 2022 Aug 23, 2022

Hi @jothipriya ,

where do you want to add a column? When at the right side of the table you could simply increase the value of columnCount of the table. Selected text frame holding a table:

 

TextFrameSelectedWithTable-1.PNG

Run this code to the selected text frame:

var myTable = app.selection[0].tables[0];
var numOfColumns = myTable.columnCount;

// Add one column:
myTable.columnCount = numOfColumns + 1;

 

Result is this:

TextFrameSelectedWithTable-2.PNG

 

Regards,
Uwe Laubender
( Adobe Community Professional )

Votes

Translate

Translate
Community Expert ,
Aug 23, 2022 Aug 23, 2022

Copy link to clipboard

Copied

LATEST

Hi @jothipriya ,

where do you want to add a column? When at the right side of the table you could simply increase the value of columnCount of the table. Selected text frame holding a table:

 

TextFrameSelectedWithTable-1.PNG

Run this code to the selected text frame:

var myTable = app.selection[0].tables[0];
var numOfColumns = myTable.columnCount;

// Add one column:
myTable.columnCount = numOfColumns + 1;

 

Result is this:

TextFrameSelectedWithTable-2.PNG

 

Regards,
Uwe Laubender
( Adobe Community Professional )

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