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!
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");*/
}
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);
}
}
}