C # uses free spire.presentation to insert and edit ppt and delete tables

Source: Internet
Author: User
Small series found to be used. NET component--free spire.presentation, in C # to add the product DLL file, you can easily and quickly implement the presentation of the table insert, edit and delete operations, the implementation of code for everyone to refer to this article

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


  Presentation ppt = new Presentation ();   Ppt. Slidesize.type = 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[] {[n   ], []] Double[] Heights = new double[] {A, a, a, A/n};   ITable table = ppt. Slides[0]. Shapes.appendtable (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[,]{   {"Rank", "name", "Sales", "Return Amount", "Work Number"},   {"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


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

Step two: Get 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 Three: Delete rows fourth and fourth


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

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


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

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


list<ishape> tableshapes = new list<ishape> ();

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


foreach (IShape shape in ppt. Slides[0]. Shapes)   {    if (Shape 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);

Summarize

Related Article

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.