Independentsoft
Home
Products
Purchase
Support
Downloads
Company
Contact
Presentation .NET
>
Tutorial
> Insert table
The following example shows you how to create new presentation with one slide and simple table.
C# example
using System; using Independentsoft.Office; using Independentsoft.Office.Drawing.Tables; using Independentsoft.Office.Presentation; using Independentsoft.Office.Presentation.Drawing; namespace Sample { class Program { static void Main(string[] args) { Presentation presentation = new Presentation(); GroupShape shapeTree = new GroupShape(); shapeTree.ID = "2"; shapeTree.Name = "ShapeTree"; shapeTree.ShapeProperties.TransformGroup2D = new Independentsoft.Office.Drawing.TransformGroup2D(); Cell cell1 = new Cell(); cell1.ShapeTextBody = new Independentsoft.Office.Drawing.ShapeTextBody(); cell1.ShapeTextBody.TextListStyle = new Independentsoft.Office.Drawing.TextListStyle(); Independentsoft.Office.Drawing.TextRun run1 = new Independentsoft.Office.Drawing.TextRun("Text 123"); Independentsoft.Office.Drawing.TextParagraph paragraph1 = new Independentsoft.Office.Drawing.TextParagraph(); paragraph1.Content.Add(run1); cell1.ShapeTextBody.Paragraphs.Add(paragraph1); Row row1 = new Row(); row1.Height = new Unit(50, UnitType.Pixel); row1.Cells.Add(cell1); row1.Cells.Add(cell1); row1.Cells.Add(cell1); Table table = new Table(); table.FirstRow = true; table.BandedRows = true; table.Grid = new TableGrid(); table.Grid.Columns.Add(new TableGridColumn(1524000)); table.Grid.Columns.Add(new TableGridColumn(1524000)); table.Grid.Columns.Add(new TableGridColumn(1524000)); table.Rows.Add(row1); Independentsoft.Office.Presentation.Drawing.GraphicFrame graphicFrame = new Independentsoft.Office.Presentation.Drawing.GraphicFrame(); graphicFrame.ID = "3"; graphicFrame.Name = "table 1"; graphicFrame.GraphicObject = table; graphicFrame.Transform2D = new Independentsoft.Office.Presentation.Drawing.Transform2D(); graphicFrame.Transform2D.Offset = new Independentsoft.Office.Drawing.Offset(1524000, 1397000); graphicFrame.Transform2D.Extents = new Independentsoft.Office.Drawing.Extents(6096000, 370840); shapeTree.Elements.Add(graphicFrame); CommonSlideData commonSlideData = new CommonSlideData(); commonSlideData.ShapeTree = shapeTree; SlideLayout layout1 = new SlideLayout(); layout1.CommonSlideData = GetLayoutCommonSlideData(); Slide slide1 = new Slide(); slide1.CommonSlideData = commonSlideData; slide1.Layout = layout1; SlideMaster master1 = new SlideMaster(); master1.CommonSlideData = GetLayoutCommonSlideData(); master1.Layouts.Add(layout1); master1.TextStyles = new SlideMasterTextStyles(); master1.TextStyles.TitleStyle = new SlideMasterTitleTextStyle(); master1.TextStyles.TitleStyle.ListLevel1TextStyle.DefaultTextRunProperties.FontSize = 44; presentation.Slides.Add(slide1); presentation.SlideMasters.Add(master1); presentation.SlideSize = new SlideSize(9144000, 6858000, SlideSizeType.Screen4x3); presentation.NotesSlideSize = new NotesSlideSize(6858000, 9144000); presentation.Save("c:\\testfolder\\presentation.pptx", true); } static CommonSlideData GetLayoutCommonSlideData() { GroupShape shapeTree = new GroupShape(); shapeTree.ID = "1"; shapeTree.Name = "layout"; shapeTree.ShapeProperties.TransformGroup2D = new Independentsoft.Office.Drawing.TransformGroup2D(); CommonSlideData commonSlideData = new CommonSlideData(); commonSlideData.ShapeTree = shapeTree; return commonSlideData; } } }
VB example
Imports System Imports Independentsoft.Office Imports Independentsoft.Office.Drawing.Tables Imports Independentsoft.Office.Presentation Imports Independentsoft.Office.Presentation.Drawing Module Module1 Sub Main(ByVal args As String()) Dim presentation As New Presentation() Dim shapeTree As New GroupShape() shapeTree.ID = "2" shapeTree.Name = "ShapeTree" shapeTree.ShapeProperties.TransformGroup2D = New Independentsoft.Office.Drawing.TransformGroup2D() Dim cell1 As New Cell() cell1.ShapeTextBody = New Independentsoft.Office.Drawing.ShapeTextBody() cell1.ShapeTextBody.TextListStyle = New Independentsoft.Office.Drawing.TextListStyle() Dim run1 As New Independentsoft.Office.Drawing.TextRun("Text 123") Dim paragraph1 As New Independentsoft.Office.Drawing.TextParagraph() paragraph1.Content.Add(run1) cell1.ShapeTextBody.Paragraphs.Add(paragraph1) Dim row1 As New Row() row1.Height = New Unit(50, UnitType.Pixel) row1.Cells.Add(cell1) row1.Cells.Add(cell1) row1.Cells.Add(cell1) Dim table As New Table() table.FirstRow = True table.BandedRows = True table.Grid = New TableGrid() table.Grid.Columns.Add(New TableGridColumn(1524000)) table.Grid.Columns.Add(New TableGridColumn(1524000)) table.Grid.Columns.Add(New TableGridColumn(1524000)) table.Rows.Add(row1) Dim graphicFrame As New Independentsoft.Office.Presentation.Drawing.GraphicFrame() graphicFrame.ID = "3" graphicFrame.Name = "table 1" graphicFrame.GraphicObject = table graphicFrame.Transform2D = New Independentsoft.Office.Presentation.Drawing.Transform2D() graphicFrame.Transform2D.Offset = New Independentsoft.Office.Drawing.Offset(1524000, 1397000) graphicFrame.Transform2D.Extents = New Independentsoft.Office.Drawing.Extents(6096000, 370840) shapeTree.Elements.Add(graphicFrame) Dim commonSlideData As New CommonSlideData() commonSlideData.ShapeTree = shapeTree Dim layout1 As New SlideLayout() layout1.CommonSlideData = GetLayoutCommonSlideData() Dim slide1 As New Slide() slide1.CommonSlideData = commonSlideData slide1.Layout = layout1 Dim master1 As New SlideMaster() master1.CommonSlideData = GetLayoutCommonSlideData() master1.Layouts.Add(layout1) master1.TextStyles = New SlideMasterTextStyles() master1.TextStyles.TitleStyle = New SlideMasterTitleTextStyle() master1.TextStyles.TitleStyle.ListLevel1TextStyle.DefaultTextRunProperties.FontSize = 44 presentation.Slides.Add(slide1) presentation.SlideMasters.Add(master1) presentation.SlideSize = New SlideSize(9144000, 6858000, SlideSizeType.Screen4x3) presentation.NotesSlideSize = New NotesSlideSize(6858000, 9144000) presentation.Save("c:\testfolder\presentation.pptx", True) End Sub Function GetLayoutCommonSlideData() As CommonSlideData Dim shapeTree As New GroupShape() shapeTree.ID = "1" shapeTree.Name = "layout" shapeTree.ShapeProperties.TransformGroup2D = New Independentsoft.Office.Drawing.TransformGroup2D() Dim commonSlideData As New CommonSlideData() commonSlideData.ShapeTree = shapeTree Return commonSlideData End Function End Module