Skip to main content
jothipriya
Inspiring
August 23, 2022
Answered

Add New Column to existing table

  • August 23, 2022
  • 1 reply
  • 390 views

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

This topic has been closed for replies.
Correct answer Laubender

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:

 

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:

 

Regards,
Uwe Laubender
( Adobe Community Professional )

1 reply

LaubenderCorrect answer
Community Expert
August 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:

 

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:

 

Regards,
Uwe Laubender
( Adobe Community Professional )