Esempio n. 1
0
        public void OverwriteStyleDifferentDocument()
        {
            Aspose.Words.Document dstDoc = new Aspose.Words.Document();
            Aspose.Words.Document srcDoc = new Aspose.Words.Document();

            //ExStart
            //ExFor:StyleCollection.AddCopy
            //ExId:OverwriteStyleDifferentDocument
            //ExSummary:Demonstrates how to copy a style from one document to another and overide an existing style in the destination document.
            // This is the style in the source document to copy to the destination document.
            Aspose.Words.Style srcStyle = srcDoc.Styles[StyleIdentifier.Heading1];

            // Change the font of the heading style to red.
            srcStyle.Font.Color = Color.Red;

            // The AddCopy method can be used to copy a style to a different document.
            Aspose.Words.Style newStyle = dstDoc.Styles.AddCopy(srcStyle);

            // The name of the new style can be changed to the name of any existing style. Doing this will override the existing style.
            newStyle.Name = "Heading 1";
            //ExEnd

            Assert.NotNull(newStyle);
            Assert.AreEqual("Heading 1", newStyle.Name);
            Assert.IsNull(dstDoc.Styles["Heading 1_0"]);
            Assert.AreEqual(Color.Red.ToArgb(), newStyle.Font.Color.ToArgb());
        }
Esempio n. 2
0
        public void Style()
        {
            //ExStart
            //ExFor:Font.Style
            //ExFor:Style.BuiltIn
            //ExSummary:Applies double underline to all runs in a document that are formatted with custom character styles.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Font.Style.doc");

            // Select all run nodes in the document.
            NodeCollection runs = doc.GetChildNodes(NodeType.Run, true);

            // Loop through every run node.
            foreach (Run run in runs)
            {
                Aspose.Words.Style charStyle = run.Font.Style;

                // If the style of the run is not a built-in character style, apply double underline.
                if (!charStyle.BuiltIn)
                {
                    run.Font.Underline = Underline.Double;
                }
            }

            doc.Save(MyDir + "Font.Style Out.doc");
            //ExEnd
        }
Esempio n. 3
0
        public void CopyStyleSameDocument()
        {
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Document.doc");

            //ExStart
            //ExFor:StyleCollection.AddCopy
            //ExFor:Style.Name
            //ExSummary:Demonstrates how to copy a style within the same document.
            // The AddCopy method creates a copy of the specified style and automatically generates a new name for the style, such as "Heading 1_0".
            Aspose.Words.Style newStyle = doc.Styles.AddCopy(doc.Styles["Heading 1"]);

            // You can change the new style name if required as the Style.Name property is read-write.
            newStyle.Name = "My Heading 1";
            //ExEnd

            Assert.NotNull(newStyle);
            Assert.AreEqual("My Heading 1", newStyle.Name);
            Assert.AreEqual(doc.Styles["Heading 1"].Type, newStyle.Type);
        }
Esempio n. 4
0
        public void CopyStyleDifferentDocument()
        {
            Aspose.Words.Document dstDoc = new Aspose.Words.Document();
            Aspose.Words.Document srcDoc = new Aspose.Words.Document();

            //ExStart
            //ExFor:StyleCollection.AddCopy
            //ExSummary:Demonstrates how to copy style from one document into a different document.
            // This is the style in the source document to copy to the destination document.
            Aspose.Words.Style srcStyle = srcDoc.Styles[StyleIdentifier.Heading1];

            // Change the font of the heading style to red.
            srcStyle.Font.Color = Color.Red;

            // The AddCopy method can be used to copy a style from a different document.
            Aspose.Words.Style newStyle = dstDoc.Styles.AddCopy(srcStyle);
            //ExEnd

            Assert.NotNull(newStyle);
            Assert.AreEqual("Heading 1", newStyle.Name);
            Assert.AreEqual(Color.Red.ToArgb(), newStyle.Font.Color.ToArgb());
        }
Esempio n. 5
0
        public void ParagraphStyleBulleted()
        {
            //ExStart
            //ExFor:StyleCollection
            //ExFor:DocumentBase.Styles
            //ExFor:Style
            //ExFor:Font
            //ExFor:Style.Font
            //ExFor:Style.ParagraphFormat
            //ExFor:Style.ListFormat
            //ExFor:ParagraphFormat.Style
            //ExSummary:Shows how to create and use a paragraph style with list formatting.
            Aspose.Words.Document doc     = new Aspose.Words.Document();
            DocumentBuilder       builder = new DocumentBuilder(doc);

            // Create a paragraph style and specify some formatting for it.
            Aspose.Words.Style style = doc.Styles.Add(StyleType.Paragraph, "MyStyle1");
            style.Font.Size = 24;
            style.Font.Name = "Verdana";
            style.ParagraphFormat.SpaceAfter = 12;

            // Create a list and make sure the paragraphs that use this style will use this list.
            style.ListFormat.List            = doc.Lists.Add(ListTemplate.BulletDefault);
            style.ListFormat.ListLevelNumber = 0;

            // Apply the paragraph style to the current paragraph in the document and add some text.
            builder.ParagraphFormat.Style = style;
            builder.Writeln("Hello World: MyStyle1, bulleted.");

            // Change to a paragraph style that has no list formatting.
            builder.ParagraphFormat.Style = doc.Styles["Normal"];
            builder.Writeln("Hello World: Normal.");

            builder.Document.Save(MyDir + "Lists.ParagraphStyleBulleted Out.doc");
            //ExEnd
        }
Esempio n. 6
0
        public void CreateAndUseListStyle()
        {
            //ExStart
            //ExFor:StyleCollection.Add(StyleType,String)
            //ExFor:Style.List
            //ExFor:StyleType
            //ExFor:List.IsListStyleDefinition
            //ExFor:List.IsListStyleReference
            //ExFor:List.IsMultiLevel
            //ExFor:List.Style
            //ExFor:ListLevelCollection
            //ExFor:ListLevelCollection.Count
            //ExFor:ListLevelCollection.Item
            //ExFor:ListCollection.Add(Style)
            //ExSummary:Shows how to create a list style and use it in a document.
            Aspose.Words.Document doc = new Aspose.Words.Document();

            // Create a new list style.
            // List formatting associated with this list style is default numbered.
            Aspose.Words.Style listStyle = doc.Styles.Add(StyleType.List, "MyListStyle");

            // This list defines the formatting of the list style.
            // Note this list can not be used directly to apply formatting to paragraphs (see below).
            Aspose.Words.Lists.List list1 = listStyle.List;

            // Check some basic rules about the list that defines a list style.
            Console.WriteLine("IsListStyleDefinition: " + list1.IsListStyleDefinition);
            Console.WriteLine("IsListStyleReference: " + list1.IsListStyleReference);
            Console.WriteLine("IsMultiLevel: " + list1.IsMultiLevel);
            Console.WriteLine("List style has been set: " + (listStyle == list1.Style));

            // Modify formatting of the list style to our liking.
            for (int i = 0; i < list1.ListLevels.Count; i++)
            {
                ListLevel level = list1.ListLevels[i];
                level.Font.Name  = "Verdana";
                level.Font.Color = Color.Blue;
                level.Font.Bold  = true;
            }


            // Add some text to our document and use the list style.
            DocumentBuilder builder = new DocumentBuilder(doc);

            builder.Writeln("Using list style first time:");

            // This creates a list based on the list style.
            Aspose.Words.Lists.List list2 = doc.Lists.Add(listStyle);

            // Check some basic rules about the list that references a list style.
            Console.WriteLine("IsListStyleDefinition: " + list2.IsListStyleDefinition);
            Console.WriteLine("IsListStyleReference: " + list2.IsListStyleReference);
            Console.WriteLine("List Style has been set: " + (listStyle == list2.Style));

            // Apply the list that references the list style.
            builder.ListFormat.List = list2;
            builder.Writeln("Item 1");
            builder.Writeln("Item 2");
            builder.ListFormat.RemoveNumbers();


            builder.Writeln("Using list style second time:");

            // Create and apply another list based on the list style.
            Aspose.Words.Lists.List list3 = doc.Lists.Add(listStyle);
            builder.ListFormat.List = list3;
            builder.Writeln("Item 1");
            builder.Writeln("Item 2");
            builder.ListFormat.RemoveNumbers();

            builder.Document.Save(MyDir + "Lists.CreateAndUseListStyle Out.doc");
            //ExEnd

            // Verify properties of list 1
            Assert.IsTrue(list1.IsListStyleDefinition);
            Assert.IsFalse(list1.IsListStyleReference);
            Assert.IsTrue(list1.IsMultiLevel);
            Assert.AreEqual(listStyle, list1.Style);

            // Verify properties of list 2
            Assert.IsFalse(list2.IsListStyleDefinition);
            Assert.IsTrue(list2.IsListStyleReference);
            Assert.AreEqual(listStyle, list2.Style);
        }