News Category

How to Apply Built-in Style to PowerPoint Table in C#, VB.NET

2014-12-18 07:38:23 Written by  support iceblue
Rate this item
(0 votes)

Built-in table styles are predefined formatting options that can be quickly applied to any table, greatly enhancing its appearance and readability. As same as MS PowerPoint, Spire.Presentation provides such a feature to give your table a professional look by applying a certain built-in table style. This article presents how this purpose can be achieved using Spire.Presentation with C#, VB.NET.

As we can see from below picture, plain tale is not that attractive before applying any style.

How to Apply Built-in Style to PowerPoint Table in C#, VB.NET

Code Snippet for Applying Table Style:

Step 1: Create an instance of presentation and load the test file.

Presentation ppt = new Presentation("test.pptx", FileFormat.Pptx2010);

Step 2: Get the table from presentation slide.

ITable table = ppt.Slides[0].Shapes[1] as ITable;

Step 3: Choose one table style from TableStylePreset and apply it to selected table.

table.StylePreset = TableStylePreset.MediumStyle2Accent2;

Step 4: Save the file.

ppt.SaveToFile("Result.pptx", FileFormat.Pptx2010);

Output:

How to Apply Built-in Style to PowerPoint Table in C#, VB.NET

Full Code:

[C#]
using Spire.Presentation;

namespace Apply_Built_in_Style
{

    class Program
    {

        static void Main(string[] args)
        {
            Presentation ppt = new Presentation("test.pptx", FileFormat.Pptx2010);
            ITable table = ppt.Slides[0].Shapes[1] as ITable;
            table.StylePreset = TableStylePreset.MediumStyle2Accent2;
            ppt.SaveToFile("Result.pptx", FileFormat.Pptx2010);

        }

    }
}
[VB.NET]
Imports Spire.Presentation

Namespace Apply_Built_in_Style

	Class Program

		Private Shared Sub Main(args As String())
			Dim ppt As New Presentation("test.pptx", FileFormat.Pptx2010)
			Dim table As ITable = TryCast(ppt.Slides(0).Shapes(1), ITable)
			table.StylePreset = TableStylePreset.MediumStyle2Accent2
			ppt.SaveToFile("Result.pptx", FileFormat.Pptx2010)

		End Sub

	End Class
End Namespace

Additional Info

  • tutorial_title: Apply Built-in Style to PowerPoint Table
Last modified on Friday, 24 September 2021 09:22