C # insert, edit, and delete tables in a PPT,
In modern learning and office systems, applications of tables are often used, such as various documents, reports, and accounts. It is also inevitable to apply various data tables in PPT presentations. I found a new method for inserting a table in the PPT, but I used a free one. NET component -- Free Spire. presentation: add the DLL file of the product in C # To insert, edit, and delete tables in the Presentation. If you need to download in the following url: https://www.e-iceblue.cn/Downloads/Free-Spire-Presentation-NET.html
1.Insert table
Step 1: Create a PowerPoint document
Presentation ppt = new Presentation(); ppt.SlideSize.Type = SlideSizeType.Screen16x9;
Step 2: Initialize an ITable instance and specify the location, number of rows, number of columns, row height, and column width.
double[] widths = new double[] { 100, 100, 100, 100, 100 }; double[] heights = new double[] { 15, 15, 15, 15, 15 }; ITable table = ppt.Slides[0].Shapes.AppendTable(80, 80, widths, heights);
Step 3: Set the built-in format for the table
table.StylePreset = TableStylePreset.LightStyle1Accent2;
Step 4: declare and initialize a String [,] Array
String [,] data = new string [,] {"rank", "name", "sales", "Return amount", "employee ID" },{ "1 ", "Li Biao", "18270", "18270", "0011" },{ "2", "Li Na", "18105", "18105", "0025 "}, {"3", "Zhang Li", "17987", "17987", "0008" },{ "4", "Huang Yan", "17790", "17790 ", "0017 "},};
Step 6: Save the document
Ppt. SaveToFile ("create table format .pptx", FileFormat. Pptx2010 );
After completing the operation, you can get the following PPT documents
2. Delete table rows and columns
Step 1: initialize a Presentation instance and load a PowerPoint file
Presentation ppt = new Presentation (); ppt. LoadFromFile (@ "C: \ Users \ Administrator \ Desktop \ create table grid .pptx ");
Step 2: Obtain the table on the first slide
ITable table = null; foreach (IShape shape in ppt.Slides[0].Shapes) { if (shape is ITable) { table = (ITable)shape;
Step 3: Delete the fourth and fourth columns
table.ColumnsList.RemoveAt(3, false; table.TableRows.RemoveAt(4, false;
Step 4: Save the document
Ppt. SaveToFile ("Delete row and column .pptx", FileFormat. Pptx2010 );
3. delete a table
Step 1: initialize a Presentation instance and load a PowerPoint file
Presentation ppt = new Presentation (); ppt. LoadFromFile (@ "C: \ Users \ Administrator \ Desktop \ create table grid .pptx ");
Step 2: initialize a List object with the element type IShape
List<IShape> tableShapes = new List<IShape>();
Step 3: obtain all the table images on the first slide and add them to the List
foreach (IShape shape in ppt.Slides[0].Shapes) { if (shape is ITable) { tableShapes.Add(shape); } }
Step 4: Delete the first table image from the slide
ppt.Slides[0].Shapes.Remove(tableShapes[0]);
Step 5: Save the document
Ppt. SaveToFile ("Delete table lattice .pptx", FileFormat. Pptx2010 );
I have used the Free Spire. Presentation component to perform some operations on the tables in the PPT document. Thank you for reading this article!