Various kinds of shapes like triangle, rectangle, ellipse, star, line and etc, can be created with Spire.Presentation. To make shapes more compatible with the entire slide, not only can we set color and choose fill style of the shape, we can also rotate shapes to a desired degree. This article is aimed to provide a simple example.

To begin with, create or open a .NET class application in Visual Studio 2005 or above versions, add Spire.Presentation.dll to your .NET project assemblies. Then, you are able create and format shapes using the sample C# code we have offered below.

Code snippets for rotate shapes on slide:

Step 1: Create an instance of Presentation class.

Presentation presentation = new Presentation();

Step 2: Add a new shape - Triangle ,to PPT slide.

IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Triangle, new RectangleF(100, 100, 100, 100));

Step 3: Rotate the shape to 180 degree.

shape.Rotation = 180;  

Step 4: Set the color and fill style of shape.

shape.Fill.FillType = FillFormatType.Solid;
shape.Fill.SolidColor.Color = Color.BlueViolet;
shape.ShapeStyle.LineColor.Color = Color.Black;

Step 5: Save and launch the file.

presentation.SaveToFile("shape.pptx", FileFormat.Pptx2010);
System.Diagnostics.Process.Start("shape.pptx");

Effect Screenshot:

Rotate Shapes on PowerPoint Slide with .NET

Full code:

[C#]
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;

namespace RotateShape
{

    class Program
    {

        static void Main(string[] args)
        {
           //create PPT document 
            Presentation presentation = new Presentation();

            //append new shape - Triangle
            IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Triangle, new RectangleF(100, 100, 100, 100));                     
            //set rotation to 180
            shape.Rotation = 180;  

            //set the color and fill style of shape
            shape.Fill.FillType = FillFormatType.Solid;
            shape.Fill.SolidColor.Color = Color.BlueViolet;
            shape.ShapeStyle.LineColor.Color = Color.Black;

            //save the document
            presentation.SaveToFile("shape.pptx", FileFormat.Pptx2010);
            System.Diagnostics.Process.Start("shape.pptx");
        }

        }
    }
[VB.NET]
Imports Spire.Presentation
Imports Spire.Presentation.Drawing
Imports System.Drawing

Namespace RotateShape

	Class Program

		Private Shared Sub Main(args As String())
			'create PPT document 
			Dim presentation As New Presentation()

			'append new shape - Triangle
			Dim shape As IAutoShape = presentation.Slides(0).Shapes.AppendShape(ShapeType.Triangle, New RectangleF(100, 100, 100, 100))
			'set rotation to 180
			shape.Rotation = 180

			'set the color and fill style of shape
			shape.Fill.FillType = FillFormatType.Solid
			shape.Fill.SolidColor.Color = Color.BlueViolet
			shape.ShapeStyle.LineColor.Color = Color.Black

			'save the document
			presentation.SaveToFile("shape.pptx", FileFormat.Pptx2010)
			System.Diagnostics.Process.Start("shape.pptx")
		End Sub

	End Class
End Namespace

Replace Text in Word with Table in C#

2014-08-07 03:54:58 Written by Koohji

This topic is just another request from one of our users on Spire.Doc Forum. In order to let more people know about this function, we’re going to present the whole procedure through a sample demo in the article. Additionally, we would like to remind you that we offer free customized demo for both pay users and test users.

As a professional .NET Word component, Spire.Doc enables developers to replace specified paragraph with a newly created table or an existing table. In this example, the paragraph 3 in main body of the sample word file will be replaced by a newly-built table.

Test file:

Replace Text in Word with Table in C#

Code snippets for replacing text with table:

Step 1: Create a new word document and load the test file.

Document doc = new Document();
doc.LoadFromFile(@"..\..\test.docx");

Step 2: Return TextSection by finding the key text string "classical antiquity science".

Section section = doc.Sections[0];     
TextSelection selection = doc.FindString("classical antiquity science", true, true);

Step 3: Return TextRange from TextSection, then get OwnerParagraph through TextRange.

TextRange range = selection.GetAsOneRange();
Paragraph paragraph = range.OwnerParagraph;

Step 4: Return the zero-based index of the specified paragraph.

Body body = paragraph.OwnerTextBody;
int index = body.ChildObjects.IndexOf(paragraph);

Step 5: Create a new table.

Table table = section.AddTable(true);
table.ResetCells(3, 3);

Step 6: Remove the paragraph and insert table into the collection at the specified index.

body.ChildObjects.Remove(paragraph);
body.ChildObjects.Insert(index, table);

Step 7: Save and launch the file.

doc.SaveToFile("result.doc", FileFormat.Doc);
System.Diagnostics.Process.Start("result.doc");

Result:

Replace Text in Word with Table in C#

Full C# code:

using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
namespace ReplaceText
{

    class Program
    {
        static void Main(string[] args)
        {
            Document doc = new Document();
            doc.LoadFromFile(@"..\..\test.docx");
            Section section = doc.Sections[0];
            TextSelection selection = doc.FindString("classical antiquity science", true, true);
            TextRange range = selection.GetAsOneRange();
            Paragraph paragraph = range.OwnerParagraph;
            Body body = paragraph.OwnerTextBody;
            int index = body.ChildObjects.IndexOf(paragraph);

            Table table = section.AddTable(true);
            table.ResetCells(3, 3);
            body.ChildObjects.Remove(paragraph);
            body.ChildObjects.Insert(index, table);

            doc.SaveToFile("result.doc", FileFormat.Doc);
            System.Diagnostics.Process.Start("result.doc");

        }
    }
}

Word bookmarks are widely used for point out a specified location or give brief information of the paragraph. If you add an image into the bookmark position, the bookmarks will be more obviously and clearly. This article will show you how to insert an image at bookmark position in C# with the help of Spire.Doc.

Spire.Doc offers an instance of BookmarksNavigator to find the bookmarks, and then developers use AppendPicture to add an image. Here comes to the steps:

Step 1: Load a word documents with bookmarks.

Document document = new Document();
document.LoadFromFile("Test.docx");

Step 2: Create an instance of BookmarksNavigator and find the bookmark where you want to insert an image.

//Create an instance of BookmarksNavigator
BookmarksNavigator bn = new BookmarksNavigator(document);
//Find a bookmark and its name is Spire
bn.MoveToBookmark("Spire", true, true);

Step 3: Insert an image at the position of bookmarks you found.

//Add a section and named it section0
Section section0 = document.AddSection();
//Add a paragraph for section0
Paragraph paragraph = section0.AddParagraph();
Image image = Image.FromFile("step.png");
//Add a picture into paragraph
DocPicture picture = paragraph.AppendPicture(image);
//Add a paragraph with picture at the position of bookmark
bn.InsertParagraph(paragraph);
document.Sections.Remove(section0);

Step 4: Save the new document and process it.

string output = "sample3.docx";
document.SaveToFile(output, FileFormat.Docx);
System.Diagnostics.Process.Start(output);

Spire.Doc also offers the following properties to set the image position based on developers' requirements.

picture.TextWrappingStyle
picture.HorizontalAlignment
picture.HorizontalOrigin
picture.HorizontalPosition
picture.VerticalAlignment
picture.VerticalOrigin
picture.VerticalPosition

Effective screenshot:

Insert an image at bookmark in word documents

Full codes:

using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;
namespace InsertImage
{
    class Program
    {

        static void Main(string[] args)
        {

            Document document = new Document();
            document.LoadFromFile("Test.docx");
            BookmarksNavigator bn = new BookmarksNavigator(document);
            bn.MoveToBookmark("Spire", true, true);
            Section section0 = document.AddSection();
            Paragraph paragraph = section0.AddParagraph();
            Image image = Image.FromFile("step.png");
            DocPicture picture = paragraph.AppendPicture(image);
            bn.InsertParagraph(paragraph);
            document.Sections.Remove(section0);
            string output = "sample.docx";
            document.SaveToFile(output, FileFormat.Docx);
            System.Diagnostics.Process.Start(output);
        }
    }
}
page 259