C # Implementation of INSERT, edit, delete table for PPT

Source: Internet
Author: User

In modern learning and office, the use of forms is often exposed, such as various documents, statements, accounts, etc. The same inevitably applies to various data tables in PowerPoint presentations. I found a new way to insert a table in ppt, but I used a free one. NET component--free Spire.presentation, add the product DLL file in C # to quickly and easily implement table insertions, edits, and deletions to your presentation. If necessary, you can download it at the following URL: https://www.e-iceblue.cn/Downloads/Free-Spire-Presentation-NET.html

1. Insert Table

Step one: Create a PowerPoint document

            New Presentation ();             = slidesizetype.screen16x9;

Step two: Initialize a itable instance and specify the position, number of rows and columns, row height, and column width

 double  [] widths = new  double  [] {100 , 100 , 100 , 100 , 100             };  double  [] Heights = new  double  [] {15 , 15 ," Span style= "COLOR: #800080" >15 , 15 , 15             }; ITable table  = ppt. Slides[0 ]. Shapes.appendtable (80 , 80 , widths, Heights); 

Step three: Set the built-in format for the table

            Table. Stylepreset = Tablestylepreset.lightstyle1accent2;

Step four: Declare and initialize a string[,] array

            string[,] data =New string[,]{            {"ranking","name","Sales","Return amount","Work No."},            {"1","Libiao","18270","18270","0011"},            {"2","Li Na","18105","18105","0025"},            {"3","Zhang Li","17987","17987","0008"},            {"4","Huang Yan","17790","17790","0017"},};

Step Six: Save the document

            Ppt. SaveToFile (" create table. pptx", fileformat.pptx2010);

After completing the operation, get the following PPT document effect

2. Delete Table rows and columns

Step One: Initialize a presentation instance and load a PowerPoint document

            New Presentation ();            Ppt. LoadFromFile (@ "C:\Users\Administrator\Desktop\ create table. pptx");

Step two: Get the table on the first slide

            NULL ;             foreach  in ppt. slides[0]. Shapes)            {                if is ITable)                {                    = (ITable) shape;

Step Three: Delete rows fourth and fourth

                    Table. Columnslist.removeat (3false;                    Table. Tablerows.removeat (4false;

Step Four: Save the document

            Ppt. SaveToFile (" Delete rows and columns. pptx", fileformat.pptx2010);

3. Delete a table

Step One: Initialize a presentation instance and load a PowerPoint document

            New Presentation ();            Ppt. LoadFromFile (@ "C:\Users\Administrator\Desktop\ create table. pptx");

Step Two: Initialize a list object with an element type of IShape

            New List<ishape> ();

Step three: Get all the table graphics on the first slide and add to the list

            foreach  in ppt. slides[0]. Shapes)            {                if is ITable)                {                    tableshapes.add (shape);                }            }

Step four: Remove the first table graphic from a slide

            Ppt. slides[0]. Shapes.remove (tableshapes[0]);

Step Five: Save the document

            Ppt. SaveToFile (" delete table. pptx", fileformat.pptx2010);

Above is I use free spire.presentation this component to PPT document form of some operation, hope can provide help, thank reading!

C # Implementation of INSERT, edit, delete table for PPT

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.