We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Insert COlumn to table

How to insert column to a table object between other columns
This message was posted using Aspose.Live 2 Forum

Hi,

I Work at Assette Softwares, we hold licensed version of Aspose.Slides for .net, i just want to know how do i insert a column to an existing table between existing columns. just like in PowerPoint we have option to insert column to left /right.

Thanks,
Aneef

Hi Aneef,

Thanks for your interest in Aspose.Slides.

I am extremely sorry for the delayed response as I am still awaiting response from my development team about state of your issue. The AddColumn() method is available in Table Class, that actually clones the last column and add the column in end. As a way out, you may device your own logic to add column in the middle of table by using AddColumn method and then shifting the columns to one step ahead from location where you want to insert new column. This that column will be available in the middle of table. However, I am still awaiting response from development team and as soon as some input is received from them, I will share that with you.

We are sorry for your inconvenience,

Hi Mudasser,

Thanks for the update. i understand that we can add new column at the end of the table. but how do we move this column to the required position ?. i couldn’t see any way of doing it in your documentation. please update.

Thanks,
Aneef

Hi Aneef,

I regret to inform you that there is no property associated with Table or Column class to set or change the position of the column. However, you can manage that programmatically by shifting the contents of columns. For your reference, please follow the code snippet below, as this will help you to set the column in between table by moving the contents of columns. This may give you an idea and you may tailor it your self to meet your requirements.

//Instantiate a Presentation object that represents a PPT file

Presentation pres = new Presentation();

Slide slide= pres.AddEmptySlide();

FontEntity fntEnt = pres.Fonts[0];

FontEntity fntEntNew = new FontEntity(pres,fntEnt);

fntEntNew.FontName = "Comic Sans MS";

int fntEntNewIdx = pres.Fonts.Add(fntEntNew);

//Accessing a slide using its slide position

//Slide slide = pres.GetSlideByPosition(2);

//Setting table parameters

int xPosition = 880;

int yPosition = 1400;

int tableWidth = 4000;

int tableHeight = 500;

int columns = 4;

int rows = 4;

double borderWidth = 2;

//Adding a new table to the slide using specified table parameters

Aspose.Slides.Table table = slide.Shapes.AddTable(xPosition, yPosition, tableWidth, tableHeight,

columns, rows, borderWidth, Color.Blue);

//Setting the alternative text for the table that can help in future to find

//and identify this specific table

table.AlternativeText = "myTable";

//Merging two cells

table.MergeCells(table.GetCell(0, 0), table.GetCell(1, 0));

//Accessing the text frame of the first cell of the first row in the table

TextFrame tFrame;

//Adding some values to table cells

for (int col = 0; col < table.ColumnsNumber; col++)

{

for (int row = 0; row < table.RowsNumber; row++)

{

tFrame = table.GetCell(col, row).TextFrame;

tFrame.Paragraphs[0].Portions[0].Text = "COl: " + col + " ROW: " + row;

}

}

table.AddColumn();

Aspose.Slides.Cell tCellSource,tCellDest ;

// Here onwards we will shift the columns

int iDesiredColIndex=2; //Column to be inserted in middle

for (int col = table.ColumnsNumber - 2; col >= iDesiredColIndex - 1; col--)

{

for (int row = 0; row < table.RowsNumber; row++)

{

tCellSource = table.GetCell(col, row);

tCellDest = table.GetCell(col + 1, row);

tCellDest.TextFrame.Paragraphs[0].Text = tCellSource.TextFrame.Paragraphs[0].Text;

tCellSource.TextFrame.Paragraphs[0].Text = "";

}

}

//Writing the presentation as a PPT file

pres.Write("D:\\TestTable.ppt");

Thanks and Regards,