Spire.Presentation is a professional PowerPoint® compatible library that enables developers to create, read, write, modify, convert and Print PowerPoint documents. Get free and professional technical support for Spire.Presentation for .NET, Java, Android, C++, Python.

Wed Mar 01, 2023 10:14 am

How do I set the table's width and height as a whole without setting each and every data cells?
I'm simply setting it like I normally do with other shapes. See the example code below.

Code: Select all
table.Height = 50;
table.Width =  20;


The table in the code above is ITable. I did notice that even if I set those properties manually using Visual Studio watch, it doesn't do anything.
Versions tested:
- Spire.Presentation for .NET 7.8.0 and 8.2.0

boncyrus
 
Posts: 20
Joined: Wed Mar 01, 2023 10:01 am

Fri Mar 03, 2023 1:23 am

Hi,

Thanks for your inquiry.
When you are creating a table, you need to specify the height of rows and the width of columns, our Spire. Presentation will calculate table data based on the information you provided. After the table is created, if you want to reassign the width and height, our Spire. Presentation does not know how to allocate these values, so the reassignment will fail.
If you have any questions, just feel free to contact us.

Sincerely,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Fri Mar 03, 2023 9:49 am

So you cannot change the height and width of a table shape if it already exists?

This is what we are trying to do, look at the before and after in the image:

Resize table shape.png


Is this above not possible? If so, please share the code snippet.

Here is the pptx:

Move table shape.zip

majeed_s
 
Posts: 80
Joined: Thu Mar 25, 2021 4:13 pm

Mon Mar 06, 2023 6:41 am

Hi,

Thanks for your inquiry.
Adjusting the table’s width and height as a whole is not available, but you can adjust the width and height of each cell can also achieve the same effect. Please see the following code for reference.
Code: Select all
            Presentation ppt = new Presentation();
            ppt.LoadFromFile("Move table shape.pptx");
            ITable table;
            // for example, set the table's width and length you want
            double tableWidth = 87;
            double tableHeight = 170;
            foreach (IShape shape in ppt.Slides[0].Shapes)
            {
                if (shape is ITable)
                {
                    table = (ITable)shape;

                    for (int i = 0; i < table.TableRows.Count; i++)
                    {
                        table.TableRows[i].Height = tableWidth/table.TableRows.Count;
                    }

                    for (int i = 0; i < table.ColumnsList.Count; i++)
                    {
                        table.ColumnsList[i].Width = tableHeight/ table.ColumnsList.Count;
                    }
                }
            }
            ppt.SaveToFile("output.pptx", FileFormat.Pptx2013);

If the code does not meet your requirement or you have further questions, just feel free to contact us.

Sincerely,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Wed Mar 08, 2023 12:30 pm

Thanks for confirming. No other question on this.

majeed_s
 
Posts: 80
Joined: Thu Mar 25, 2021 4:13 pm

Thu Mar 09, 2023 2:22 am

Hi,

Thanks for your feedback.
You're welcome! If you have any other questions, just feel free to contact us.

Sincerely,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Return to Spire.Presentation

cron