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.

Tue Jul 05, 2022 3:06 pm

Hello Community!
Reading the How-to-Remove-Row-or-Column-in-Table document, I can't figure out how to delete an specific column in a slide with multiple tables.

For example: Delete Column 2 in Table 3.

Could you please help me?

Thank you!

elcade00
 
Posts: 4
Joined: Tue May 24, 2022 1:05 pm

Wed Jul 06, 2022 4:00 am

Hello Walter Rios,
Thanks for your inquiry. According to your description. You can refer to the following code to do this. If you have any further questions, just feel free to contact us.
Code: Select all
private void button1_Click(object sender, EventArgs e)
        {
        //Create a PPT document
        Presentation presentation = new Presentation();
        presentation.LoadFromFile(@"G:\Test\slide.pptx");

        //Get the table in PPT document
        ITable table = null;
        foreach (IShape shape in presentation.Slides[1].Shapes)
        {
         if (shape is ITable)
        {
          table = (ITable)shape;

        //Remove the second column
        table.ColumnsList.RemoveAt(1, false);

        //Remove the second row
        /*    table.TableRows.RemoveAt(1, false);*/
        }
        }
        //Save and launch the document
        presentation.SaveToFile("RemoveRowsAndColumns_result.pptx", FileFormat.Pptx2010);
        /*            System.Diagnostics.Process.Start("RemoveRowsAndColumns_result.pptx");*/
        }

Sincerely,
Simple
E-iceblue support team
User avatar

Simple.Li
 
Posts: 248
Joined: Fri Jul 01, 2022 2:33 am

Wed Jul 06, 2022 10:00 pm

Hello Simple.Li! Thank you for your help.

However, this code deletes all the second columns in all tables in the slide.
In my case I need to delete an specific column in an specific table.

For example, under certain conditions I need to delete the second column in the table 3.

See attachment.

elcade00
 
Posts: 4
Joined: Tue May 24, 2022 1:05 pm

Fri Jul 08, 2022 3:02 am

Hello Walter Rios,

Thanks for your message. You can delete an specific column in an specific table by referring to my code below. Welcome to ask again.
Code: Select all
using Spire.Presentation;

namespace WinFormsApp4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public static int TestComparison(ITable a,ITable b)
        {
            float ax = a.Left;
            float ay = a.Top;
            float bx = b.Left;
            float by = b.Top;

            if (ay < by)
            {
                return -1;
            }else if (ay > by)
            {
                return 1;
            }
            else
            {
                return ax<bx ? -1 : 1;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //Create a PPT document
            Presentation presentation = new Presentation();
            presentation.LoadFromFile(@"G:\Test\EN.pptx");

            //Get the table in PPT document
            ITable table = null;

            List<ITable> tableShapes = new List<ITable>();

            foreach (IShape shape in presentation.Slides[0].Shapes)
            {
                if (shape is ITable)
                {

                    table = (ITable)shape;
                    tableShapes.Add(table);
                   
                }
            }

            Comparison<ITable> comparison = TestComparison;
            tableShapes.Sort(comparison);
            tableShapes[2].ColumnsList.RemoveAt(1, false);

            presentation.SaveToFile("RemoveRowsAndColumns_result.pptx", FileFormat.Pptx2010);

        }
    }
}


Sincerely,
Simple
E-iceblue support team
User avatar

Simple.Li
 
Posts: 248
Joined: Fri Jul 01, 2022 2:33 am

Wed Jul 13, 2022 7:14 am

Hello Walter Rios,

Could you please let us know how is your issue going? Thanks in advance for your feedback and time.

Sincerely,
Simple
E-iceblue support team
User avatar

Simple.Li
 
Posts: 248
Joined: Fri Jul 01, 2022 2:33 am

Return to Spire.Presentation