Spire.Presentation is a professional PowerPoint® compatible library that enables developers to create, read, write, modify, convert and Print PowerPoint documents. Get free and professional technical support for Spire.Presentation for .NET, Java, Android, C++, Python.

Mon Oct 25, 2021 4:54 am

Hi

Please let me know that how to create multiple shapes in a slide .Please find the attached sample file.

Thanks in advance

pr20080798
 
Posts: 146
Joined: Wed Jan 20, 2021 1:15 pm

Mon Oct 25, 2021 9:32 am

Hello Wipro,

Thanks for your enquiry.

Please refer to the following sample code.
Code: Select all
static void Main(string[] args)
        {
            Presentation ppt = new Presentation();
            ISlide slide = ppt.Slides[0];
            //Add a new rectangle shape
            IAutoShape shape = slide.Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(25, 10, 200, 40));
            shape.Fill.FillType = FillFormatType.None;
            shape.ShapeStyle.LineColor.Color = Color.White;
            shape.TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Left;
            shape.TextFrame.Text = "Detail:Description";
            shape.TextFrame.Paragraphs[0].TextRanges[0].LatinFont = new TextFont("Calibri");
            shape.TextFrame.Paragraphs[0].TextRanges[0].Fill.FillType = FillFormatType.Solid;
            shape.TextFrame.Paragraphs[0].TextRanges[0].Fill.SolidColor.Color = Color.Black;

            //Add a new line shape
            IAutoShape line = slide.Shapes.AppendShape(ShapeType.Line, new RectangleF(25, 55, 680, 2));
            line.Line.Width = 3;
            line.Line.DashStyle = LineDashStyleType.LargeDash;
            line.ShapeStyle.LineColor.Color = Color.SkyBlue;

            //Add a new table shape
            ITable table = slide.Shapes.AppendTable(35, 68, new double[] { 320, 320 }, new double[] { 70 });
            table.SetTableBorder(TableBorderType.All, 1.5, Color.LightBlue);
            table[0, 0].FillFormat.FillType = FillFormatType.None;
            table[1, 0].FillFormat.FillType = FillFormatType.None;

            ITextFrameProperties cell1 = table[0,0].TextFrame;
            TextParagraph para0 = cell1.Paragraphs[0];
            TextRange textRange1 = new TextRange();
            textRange1.Text = "Heading1";         
            textRange1.TextUnderlineType = TextUnderlineType.Single;
            textRange1.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
            textRange1.Format.Fill.SolidColor.Color = Color.Black;
            para0.TextRanges.Append(textRange1);
            para0.Alignment = TextAlignmentType.Center;

            TextParagraph para2 = new TextParagraph();
            cell1.Paragraphs.Append(para2);
            TextRange textRange2 = new TextRange();
            textRange2.Text = "Description";
            textRange2.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
            textRange2.Format.Fill.SolidColor.Color = Color.Black;
            para2.TextRanges.Append(textRange2);       
            para2.Alignment = TextAlignmentType.Center;

            table[0, 0].TextFrame.TextRange.FontHeight = 18;
            table[0, 0].TextFrame.TextRange.LatinFont = new TextFont("Arial");


            cell1 = table[1, 0].TextFrame;
            para0 = cell1.Paragraphs[0];
            textRange1 = new TextRange();
            textRange1.Text = "Heading2";
            textRange1.TextUnderlineType = TextUnderlineType.Single;
            textRange1.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
            textRange1.Format.Fill.SolidColor.Color = Color.Black;

            para0.TextRanges.Append(textRange1);
            para0.Alignment = TextAlignmentType.Center;

            para2 = new TextParagraph();
            cell1.Paragraphs.Append(para2);
            textRange2 = new TextRange();
            textRange2.Text = "Description";
            textRange2.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
            textRange2.Format.Fill.SolidColor.Color = Color.Black;
            para2.TextRanges.Append(textRange2);
            para2.Alignment = TextAlignmentType.Center;

            table[1, 0].TextFrame.TextRange.FontHeight = 18;
            table[1, 0].TextFrame.TextRange.LatinFont = new TextFont("Arial");

            //Add a new table shape
            ITable table2 = slide.Shapes.AppendTable(35, 157, new double[] { 160, 160, 160, 160 }, new double[] { 25,45 });
            table2.SetTableBorder(TableBorderType.All, 0.5, Color.Black);
            for (int i = 0; i < 4; i++)
            {
                table2[i, 0].FillFormat.FillType = FillFormatType.Solid;
                table2[i, 0].FillFormat.SolidColor.Color = Color.Blue;
                cell1 = table2[i, 0].TextFrame;
                para0 = cell1.Paragraphs[0];
                textRange1 = new TextRange();
                textRange1.Text = "Column"+(i+1);
                textRange1.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
                textRange1.Format.Fill.SolidColor.Color = Color.White;
                para0.TextRanges.Append(textRange1);
                para0.Alignment = TextAlignmentType.Center;
            }

            cell1 = table2[0, 1].TextFrame;
            para0 = cell1.Paragraphs[0];
            textRange1 = new TextRange();
            textRange1.Text = "description";
            textRange1.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
            textRange1.Format.Fill.SolidColor.Color = Color.Black;
            para0.TextRanges.Append(textRange1);
            para0.Alignment = TextAlignmentType.Left;

            cell1 = table2[1, 1].TextFrame;
            cell1.Paragraphs.Clear();
            for (int i = 0; i < 3; i++)
            {
                para2 = new TextParagraph();
                cell1.Paragraphs.Append(para2);
                textRange2 = new TextRange();
                textRange2.Text = "Description"+(i+1);
                textRange2.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
                textRange2.Format.Fill.SolidColor.Color = Color.Black;
                para2.TextRanges.Append(textRange2);
                para2.BulletType = TextBulletType.Symbol;
                para2.BulletChar = Convert.ToChar(8226);
                para2.Alignment = TextAlignmentType.Left;
            }

            cell1 = table2[2, 1].TextFrame;
            para0 = cell1.Paragraphs[0];
            textRange1 = new TextRange();
            textRange1.Text = "Description";
            textRange1.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
            textRange1.Format.Fill.SolidColor.Color = Color.Black;
            para0.TextRanges.Append(textRange1);
            para0.Alignment = TextAlignmentType.Left;

            cell1 = table2[3, 1].TextFrame;
            cell1.IsCentered = true;
            para0 = cell1.Paragraphs[0];
            textRange1 = new TextRange();
            textRange1.Text = "Description";
            textRange1.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
            textRange1.Format.Fill.SolidColor.Color = Color.Red;
            para0.TextRanges.Append(textRange1);
            para0.Alignment = TextAlignmentType.Center;
            table2[3, 1].TextAnchorType = TextAnchorType.Center;


            //Add a round corner rectangle and set its radius
            shape = slide.Shapes.AppendRoundRectangle(25,280, 650, 70, 80);
            shape.Fill.FillType = FillFormatType.Solid;
            shape.Fill.SolidColor.Color = Color.White;
            shape.ShapeStyle.LineColor.Color = Color.SkyBlue;
            TextParagraph para = shape.TextFrame.Paragraphs[0];
            textRange1 = new TextRange();
            textRange1.Text = "Heading1";
            textRange1.TextUnderlineType = TextUnderlineType.Single;
            textRange1.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
            textRange1.Format.Fill.SolidColor.Color = Color.Black;
            textRange1.FontHeight = 15;
            para.TextRanges.Append(textRange1);
            para.Alignment = TextAlignmentType.Center;

            para2 = new TextParagraph();
            shape.TextFrame.Paragraphs.Append(para2);
            textRange2 = new TextRange();
            textRange2.Text = "Description";
            textRange2.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
            textRange2.Format.Fill.SolidColor.Color = Color.Black;
            textRange2.FontHeight = 15;
            para2.TextRanges.Append(textRange2);
            para2.Alignment = TextAlignmentType.Center;


            //Add a new rectangle shape
            shape = slide.Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(25, 380, 650, 40));
            shape.Fill.FillType = FillFormatType.Solid;
            shape.Fill.SolidColor.Color = Color.LightBlue;
            shape.Line.FillType = FillFormatType.None;

            para = shape.TextFrame.Paragraphs[0];
            textRange1 = new TextRange();
            textRange1.Text = "Heading1";
            textRange1.TextUnderlineType = TextUnderlineType.Single;
            textRange1.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
            textRange1.Format.Fill.SolidColor.Color = Color.Black;
            textRange1.FontHeight = 15;
            para.TextRanges.Append(textRange1);
            para.Alignment = TextAlignmentType.Center;

            para2 = new TextParagraph();
            shape.TextFrame.Paragraphs.Append(para2);
            textRange2 = new TextRange();
            textRange2.Text = "Description";
            textRange2.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
            textRange2.Format.Fill.SolidColor.Color = Color.Black;
            textRange2.FontHeight = 15;
            para2.TextRanges.Append(textRange2);
            para2.Alignment = TextAlignmentType.Center;
           

            string result = "multipleShapes.pptx";
            ppt.SaveToFile(result,Spire.Presentation.FileFormat.Pptx2013);
        }


Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.Presentation