Autoshapes in table with text


I have a table where I need to add autoshapes in cells. Some with text in them as well.

The shapes I need are Up Arrow, Down Arrow, Square, Circle, Diamond and Triangle. They also need to be colored differently.

Can you show me how to add these into my table?


I love the product by the way.

Dear syrik,

I have attached a source code that adds auto shapes into the cells of the tables. It is fully commented and easy to understand, if you still have any query then ask me.

Hi shakeel.faiz,
I am new here, can you pls point me where I can see your attachment?
I couldn’t see any.


Can you please elaborate your requirements in the form of sample presentation that you want to create.

Thanks for your reply.
Now, I am able to add ShapeType.TerminatorFlow and ShapeType.Ellipse in the table cell by setting the table cell X and Y at the ShapeType, so the next question is how to set the color of the Shape’s Text.
I use AddTextFrame to add the text to the shape, but don’t know how to set the color of the text.


You need to add the text on portion level inside paragraph of a text frame to set the textual property of text. Please visit this documentation link for your kind reference.

Thanks, it works.


It’s good to know things are fine on your end.

Hi mudassir,
I have issue calculating the position for AutoShape inside the table cell at middle vertical lign, pls check the attached image.
autoShape.png (28.2 KB)

Here is my calculation:
var offSetY = table.Y + cell.OffsetY;
var frameHeight = cell.Height;
float drawingHeight = frameHeight * 0.4; //40% height of cell
var frameCenter = frameHeight / 2;
var autoShapeY = offSetY + frameCenter - (drawingHeight / 2);

All these 4 tables were generated with same calculation except changing the width and height of the template table.


Apparently there seems no issue in code logic and on the basis of that the tables images on right side are correct as well. The two tables images on left seems to have issue. Please provide the working sample code along with source template presentation and generated presentation reproducing the issue on your end using latest Aspose.Slides for .NET 20.8.

I am using docker with .net core 3.1. I also found there is no issue running with debugging mode on VS.
Is it known issue?
Running on docker with .net core 3.1, when the table row height gets changed dynamically due to the data of the cell, I think at that time Y positioning gets messed up, but this is no issue with running from VS.


As requested earlier, please share the following information with us.

public class UpdateExistingTable
public static void Run()
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Tables();

        // Instantiate Presentation class that represents PPTX// Instantiate Presentation class that represents PPTX
        using (Presentation pres = new Presentation(dataDir + "UpdateExistingTable.pptx"))

            // Access the first slide
            ISlide sld = pres.Slides[0];

            // Initialize null TableEx
            ITable tbl = null;

            // Iterate through the shapes and set a reference to the table found
            foreach (IShape shp in sld.Shapes)
                if (shp is ITable)
                    tbl = (ITable)shp;

            // Set the text of the first column of second row
            //tbl[0, 1].TextFrame.Text = "New";

            var maxHeight = tbl.Rows.Max(r => r.MinimalHeight);

            for (int row = 1; row < tbl.Rows.Count; row++)
                tbl.Rows[row].MinimalHeight = maxHeight;

                var cell = tbl.Rows[row].AsICellCollection[2];
                    var offSetY = tbl.Y + cell.OffsetY;
                    var frameHeight = cell.Height;
                    float drawingHeight = (float) (frameHeight * 0.4); //40% height of cell
                    var frameCenter = frameHeight / 2;
                    var autoShapeY = (float) (offSetY + frameCenter - (drawingHeight / 2));

                    var offSetX = (float)(tbl.X + cell.OffsetX);
                    var frameWidth = cell.Width;
                    float drawingWidth = (float)(cell.Width * 0.6); //60% width of cell

                    var frameXCenter = frameWidth / 2;
                    var autoShapeX = (float)(offSetX + frameXCenter - (drawingWidth / 2));

                    sld.Shapes.AddAutoShape(ShapeType.RoundCornerRectangle, autoShapeX, autoShapeY, drawingWidth, drawingHeight);

            //Write the PPTX to Disk
            pres.Save(dataDir + "table1_out.pptx", Aspose.Slides.Export.SaveFormat.Pptx);

image.png (3.5 KB)
Update the template like this and run in docker with .net core3.1

The green line is the table.Y and cell.OffsetY, actually, this value should be the match the row of the table, but it doesn’t. The green line should overlap with white line.
image.png (58.8 KB)
As you see, the AutoShape is drawn in the middle of green lines.


I have tried to create a table in PowerPoint based on image you have shared. Can you please check the following image and attached presentation with tables that is this the desired result you are looking for. I have used your sample code as it is without any change. Therefore, I had previously requested you to please share the source presentation file (not image), generated presentation file and desired output presentation file so that I may assess further on my end.

Table (57.1 KB)