How to rotate the shape on word document in C#

Spire.Doc supports to insert new shapes to the word document and from version 6.4.11, Spire.Doc public the property ShapeObject.Rotation to enable developers to rotate the shapes. This article will show you to how to rotate the shapes on the word document in C#.

Step 1: Create a new instance of word document and load the document from file.

Document doc = new Document();
doc.LoadFromFile("Sample.docx");

Step 2: Get the first section from file.

Section section = doc.Sections[0];

Step 3: Traverse the word document and set the shape rotation as 10.

foreach (Paragraph para in section.Paragraphs)
{
    foreach (DocumentObject obj in para.ChildObjects)
    {
        if (obj is ShapeObject)
        {
            (obj as ShapeObject).Rotation = 10.0;
        }
    }
}

Step 4: Save the document to file.

doc.SaveToFile("Result.docx", FileFormat.Docx);

Effective screenshot after rotate the shapes:

How to rotate the shape on word document in C#

Full codes:

using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
namespace Rotate
{
    class Program
    {
        static void Main(string[] args)
        {
            Document doc = new Document();
            doc.LoadFromFile("Sample.docx");

            Section section = doc.Sections[0];

            foreach (Paragraph para in section.Paragraphs)
            {
                foreach (DocumentObject obj in para.ChildObjects)
                {
                    if (obj is ShapeObject)
                    {
                        (obj as ShapeObject).Rotation = 10.0;
                    }
                }
            }

            doc.SaveToFile("Result.docx", FileFormat.Docx);
        }
    }
}