Example #1
0
        public void CreatePictureBullet()
        {
            //ExStart
            //ExFor:ListLevel.CreatePictureBullet
            //ExFor:ListLevel.DeletePictureBullet
            //ExSummary:Shows how to set a custom image icon for list item labels.
            Document doc = new Document();

            List list = doc.Lists.Add(ListTemplate.BulletCircle);

            // Create a picture bullet for the current list level, and set an image from a local file system
            // as the icon that the bullets for this list level will display.
            list.ListLevels[0].CreatePictureBullet();
            list.ListLevels[0].ImageData.SetImage(ImageDir + "Logo icon.ico");

            Assert.IsTrue(list.ListLevels[0].ImageData.HasImage);

            DocumentBuilder builder = new DocumentBuilder(doc);

            builder.ListFormat.List = list;
            builder.Writeln("Hello world!");
            builder.Write("Hello again!");

            doc.Save(ArtifactsDir + "Lists.CreatePictureBullet.docx");

            list.ListLevels[0].DeletePictureBullet();

            Assert.IsNull(list.ListLevels[0].ImageData);
            //ExEnd

            doc = new Document(ArtifactsDir + "Lists.CreatePictureBullet.docx");

            Assert.IsTrue(doc.Lists[0].ListLevels[0].ImageData.HasImage);
        }
Example #2
0
        public void ApplyExistingListToParagraphs()
        {
            //ExStart
            //ExFor:ListCollection.Item(Int32)
            //ExSummary:Shows how to apply list formatting of an existing list to a collection of paragraphs.
            Document        doc     = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            builder.Writeln("Paragraph 1");
            builder.Writeln("Paragraph 2");
            builder.Write("Paragraph 3");

            NodeCollection paras = doc.GetChildNodes(NodeType.Paragraph, true);

            Assert.AreEqual(0, paras.Count(n => (n as Paragraph).ListFormat.IsListItem));

            doc.Lists.Add(ListTemplate.NumberDefault);
            List list = doc.Lists[0];

            foreach (Paragraph paragraph in paras.OfType <Paragraph>())
            {
                paragraph.ListFormat.List            = list;
                paragraph.ListFormat.ListLevelNumber = 2;
            }

            Assert.AreEqual(3, paras.Count(n => (n as Paragraph).ListFormat.IsListItem));
            //ExEnd

            doc   = DocumentHelper.SaveOpen(doc);
            paras = doc.GetChildNodes(NodeType.Paragraph, true);

            Assert.AreEqual(3, paras.Count(n => (n as Paragraph).ListFormat.IsListItem));
            Assert.AreEqual(3, paras.Count(n => (n as Paragraph).ListFormat.ListLevelNumber == 2));
        }
Example #3
0
        public void NestedLists()
        {
            //ExStart
            //ExFor:ListFormat.List
            //ExFor:ParagraphFormat.ClearFormatting
            //ExFor:ParagraphFormat.DropCapPosition
            //ExFor:ParagraphFormat.IsListItem
            //ExFor:Paragraph.IsListItem
            //ExSummary:Shows how to start a numbered list, add a bulleted list inside it, then return to the numbered list.
            Document        doc     = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            // Create an outline list for the headings
            List outlineList = doc.Lists.Add(ListTemplate.OutlineNumbers);

            builder.ListFormat.List = outlineList;
            builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;
            builder.Writeln("This is my Chapter 1");

            // Create a numbered list
            List numberedList = doc.Lists.Add(ListTemplate.NumberDefault);

            builder.ListFormat.List = numberedList;
            builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Normal;
            builder.Writeln("Numbered list item 1.");

            // Every paragraph that comprises a list will have this flag
            Assert.True(builder.CurrentParagraph.IsListItem);
            Assert.True(builder.ParagraphFormat.IsListItem);

            // Create a bulleted list
            List bulletedList = doc.Lists.Add(ListTemplate.BulletDefault);

            builder.ListFormat.List            = bulletedList;
            builder.ParagraphFormat.LeftIndent = 72;
            builder.Writeln("Bulleted list item 1.");
            builder.Writeln("Bulleted list item 2.");
            builder.ParagraphFormat.ClearFormatting();

            // Revert to the numbered list
            builder.ListFormat.List = numberedList;
            builder.Writeln("Numbered list item 2.");
            builder.Writeln("Numbered list item 3.");

            // Revert to the outline list
            builder.ListFormat.List = outlineList;
            builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;
            builder.Writeln("This is my Chapter 2");

            builder.ParagraphFormat.ClearFormatting();

            builder.Document.Save(ArtifactsDir + "Lists.NestedLists.docx");
            //ExEnd

            doc = new Document(ArtifactsDir + "Lists.NestedLists.docx");

            TestUtil.VerifyListLevel("\0)", 0.0d, NumberStyle.Arabic, doc.Lists[0].ListLevels[0]);
            TestUtil.VerifyListLevel("\0.", 18.0d, NumberStyle.Arabic, doc.Lists[1].ListLevels[0]);
            TestUtil.VerifyListLevel("\uf0b7", 18.0d, NumberStyle.Bullet, doc.Lists[2].ListLevels[0]);
        }
        public void List()
        {
            //ExStart
            //ExFor:HtmlSaveOptions.ExportListLabels
            //ExSummary:Shows how to export an indented list to .html as plain text.
            Document        doc     = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            // Use the builder to insert a list
            Aspose.Words.Lists.List list = doc.Lists.Add(ListTemplate.NumberDefault);
            builder.ListFormat.List = list;

            builder.Writeln("List item 1.");
            builder.ListFormat.ListIndent();
            builder.Writeln("List item 2.");
            builder.ListFormat.ListIndent();
            builder.Write("List item 3.");

            // When we save this to .html, normally our list will be represented by <li> tags
            // We can set this flag to have lists as plain text instead
            HtmlSaveOptions options = new HtmlSaveOptions
            {
                ExportListLabels = ExportListLabels.AsInlineText,
                PrettyFormat     = true
            };

            doc.Save(ArtifactsDir + "HtmlSaveOptions.List.html", options);
            //ExEnd
        }
Example #5
0
        public void ListDocument()
        {
            //ExStart
            //ExFor:ListCollection.Document
            //ExFor:ListCollection.Count
            //ExFor:ListCollection.Item(Int32)
            //ExFor:ListCollection.GetListByListId
            //ExFor:List.Document
            //ExFor:List.ListId
            //ExSummary:Shows how to verify owner document properties of lists.
            Document doc = new Document();

            ListCollection lists = doc.Lists;

            Assert.AreEqual(doc, lists.Document);

            List list = lists.Add(ListTemplate.BulletDefault);

            Assert.AreEqual(doc, list.Document);

            Console.WriteLine("Current list count: " + lists.Count);
            Console.WriteLine("Is the first document list: " + (lists[0].Equals(list)));
            Console.WriteLine("ListId: " + list.ListId);
            Console.WriteLine("List is the same by ListId: " + (lists.GetListByListId(1).Equals(list)));
            //ExEnd

            doc   = DocumentHelper.SaveOpen(doc);
            lists = doc.Lists;

            Assert.AreEqual(doc, lists.Document);
            Assert.AreEqual(1, lists.Count);
            Assert.AreEqual(1, lists[0].ListId);
            Assert.AreEqual(lists[0], lists.GetListByListId(1));
        }
        public void RestartListAtEachSection()
        {
            //ExStart:RestartListAtEachSection
            Document doc = new Document();

            doc.Lists.Add(ListTemplate.NumberDefault);

            List list = doc.Lists[0];

            list.IsRestartAtEachSection = true;

            DocumentBuilder builder = new DocumentBuilder(doc);

            builder.ListFormat.List = list;

            for (int i = 1; i < 45; i++)
            {
                builder.Writeln($"List Item {i}");

                if (i == 15)
                {
                    builder.InsertBreak(BreakType.SectionBreakNewPage);
                }
            }

            // IsRestartAtEachSection will be written only if compliance is higher then OoxmlComplianceCore.Ecma376.
            OoxmlSaveOptions options = new OoxmlSaveOptions {
                Compliance = OoxmlCompliance.Iso29500_2008_Transitional
            };

            doc.Save(ArtifactsDir + "WorkingWithList.RestartListAtEachSection.docx", options);
            //ExEnd:RestartListAtEachSection
        }
        public void RestartListNumber()
        {
            //ExStart:RestartListNumber
            Document        doc     = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            // Create a list based on a template.
            List list1 = doc.Lists.Add(ListTemplate.NumberArabicParenthesis);

            list1.ListLevels[0].Font.Color = Color.Red;
            list1.ListLevels[0].Alignment  = ListLevelAlignment.Right;

            builder.Writeln("List 1 starts below:");
            builder.ListFormat.List = list1;
            builder.Writeln("Item 1");
            builder.Writeln("Item 2");
            builder.ListFormat.RemoveNumbers();

            // To reuse the first list, we need to restart numbering by creating a copy of the original list formatting.
            List list2 = doc.Lists.AddCopy(list1);

            // We can modify the new list in any way, including setting a new start number.
            list2.ListLevels[0].StartAt = 10;

            builder.Writeln("List 2 starts below:");
            builder.ListFormat.List = list2;
            builder.Writeln("Item 1");
            builder.Writeln("Item 2");
            builder.ListFormat.RemoveNumbers();

            builder.Document.Save(ArtifactsDir + "WorkingWithList.RestartListNumber.docx");
            //ExEnd:RestartListNumber
        }
Example #8
0
        public void ListDocument()
        {
            //ExStart
            //ExFor:ListCollection.Document
            //ExFor:ListCollection.Count
            //ExFor:ListCollection.Item(Int32)
            //ExFor:ListCollection.GetListByListId
            //ExFor:List.Document
            //ExFor:List.ListId
            //ExSummary:Illustrates the owner document properties of lists.
            Document doc = new Document();

            ListCollection lists = doc.Lists;

            // All of these should be equal.
            Console.WriteLine("ListCollection document is doc: " + (doc == lists.Document));
            Console.WriteLine("Starting list count: " + lists.Count);

            Aspose.Words.Lists.List list = lists.Add(ListTemplate.BulletDefault);
            Console.WriteLine("List document is doc: " + (list.Document == doc));
            Console.WriteLine("List count after adding list: " + lists.Count);
            Console.WriteLine("Is the first document list: " + (lists[0] == list));
            Console.WriteLine("ListId: " + list.ListId);
            Console.WriteLine("List is the same by ListId: " + (lists.GetListByListId(1) == list));
            //ExEnd

            // Verify these properties
            Assert.AreEqual(doc, lists.Document);
            Assert.AreEqual(doc, list.Document);
            Assert.AreEqual(1, lists.Count);
            Assert.AreEqual(list, lists[0]);
            Assert.AreEqual(1, list.ListId);
            Assert.AreEqual(list, lists.GetListByListId(1));
        }
Example #9
0
        public void ApplyNewListToParagraphs()
        {
            //ExStart
            //ExFor:ListCollection.Add(ListTemplate)
            //ExSummary:Shows how to create a list by applying a new list format to a collection of paragraphs.
            Document        doc     = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            builder.Writeln("Paragraph 1");
            builder.Writeln("Paragraph 2");
            builder.Write("Paragraph 3");

            NodeCollection paras = doc.GetChildNodes(NodeType.Paragraph, true);

            Assert.AreEqual(0, paras.Count(n => (n as Paragraph).ListFormat.IsListItem));

            List list = doc.Lists.Add(ListTemplate.NumberUppercaseLetterDot);

            foreach (Paragraph paragraph in paras.OfType <Paragraph>())
            {
                paragraph.ListFormat.List            = list;
                paragraph.ListFormat.ListLevelNumber = 1;
            }

            Assert.AreEqual(3, paras.Count(n => (n as Paragraph).ListFormat.IsListItem));
            //ExEnd

            doc   = DocumentHelper.SaveOpen(doc);
            paras = doc.GetChildNodes(NodeType.Paragraph, true);

            Assert.AreEqual(3, paras.Count(n => (n as Paragraph).ListFormat.IsListItem));
            Assert.AreEqual(3, paras.Count(n => (n as Paragraph).ListFormat.ListLevelNumber == 1));
        }
Example #10
0
        public void CreatePictureBullet()
        {
            //ExStart
            //ExFor: ListLevel.CreatePictureBullet
            //ExFor: ListLevel.DeletePictureBullet
            //ExSummary: Shows how to creating and deleting picture bullet with custom image
            Document doc = new Document();

            // Create a list with template
            Aspose.Words.Lists.List list = doc.Lists.Add(ListTemplate.BulletCircle);

            // Create picture bullet for the current list level
            list.ListLevels[0].CreatePictureBullet();

            // Set your own picture bullet image through the ImageData
            list.ListLevels[0].ImageData.SetImage(this._image);

            Assert.IsTrue(list.ListLevels[0].ImageData.HasImage);

            // Delete picture bullet
            list.ListLevels[0].DeletePictureBullet();

            Assert.IsNull(list.ListLevels[0].ImageData);
            //ExEnd
        }
Example #11
0
        public void RestartNumberingUsingListCopy()
        {
            //ExStart
            //ExFor:List
            //ExFor:ListCollection
            //ExFor:ListCollection.Add(ListTemplate)
            //ExFor:ListCollection.AddCopy(List)
            //ExFor:ListLevel.StartAt
            //ExFor:ListTemplate
            //ExSummary:Shows how to restart numbering in a list by copying a list.
            Document        doc     = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            // Create a list based on a template
            List list1 = doc.Lists.Add(ListTemplate.NumberArabicParenthesis);

            // Modify the formatting of the list
            list1.ListLevels[0].Font.Color = Color.Red;
            list1.ListLevels[0].Alignment  = ListLevelAlignment.Right;

            builder.Writeln("List 1 starts below:");
            // Use the first list in the document for a while
            builder.ListFormat.List = list1;
            builder.Writeln("Item 1");
            builder.Writeln("Item 2");
            builder.ListFormat.RemoveNumbers();

            // Now I want to reuse the first list, but need to restart numbering
            // This should be done by creating a copy of the original list formatting
            List list2 = doc.Lists.AddCopy(list1);

            // We can modify the new list in any way. Including setting new start number
            list2.ListLevels[0].StartAt = 10;

            // Use the second list in the document
            builder.Writeln("List 2 starts below:");
            builder.ListFormat.List = list2;
            builder.Writeln("Item 1");
            builder.Writeln("Item 2");
            builder.ListFormat.RemoveNumbers();

            doc.Save(ArtifactsDir + "Lists.RestartNumberingUsingListCopy.docx");
            //ExEnd

            doc = new Document(ArtifactsDir + "Lists.RestartNumberingUsingListCopy.docx");

            list1 = doc.Lists[0];
            TestUtil.VerifyListLevel("\0)", 18.0d, NumberStyle.Arabic, list1.ListLevels[0]);
            Assert.AreEqual(Color.Red.ToArgb(), list1.ListLevels[0].Font.Color.ToArgb());
            Assert.AreEqual(10.0d, list1.ListLevels[0].Font.Size);
            Assert.AreEqual(1, list1.ListLevels[0].StartAt);

            list2 = doc.Lists[1];
            TestUtil.VerifyListLevel("\0)", 18.0d, NumberStyle.Arabic, list2.ListLevels[0]);
            Assert.AreEqual(Color.Red.ToArgb(), list2.ListLevels[0].Font.Color.ToArgb());
            Assert.AreEqual(10.0d, list2.ListLevels[0].Font.Size);
            Assert.AreEqual(10, list2.ListLevels[0].StartAt);
        }
Example #12
0
        public void CreateListRestartAfterHigher()
        {
            //ExStart
            //ExFor:ListLevel.NumberStyle
            //ExFor:ListLevel.NumberFormat
            //ExFor:ListLevel.IsLegal
            //ExFor:ListLevel.RestartAfterLevel
            //ExFor:ListLevel.LinkedStyle
            //ExFor:ListLevelCollection.GetEnumerator
            //ExSummary:Shows how to create a list with some advanced formatting.
            Document        doc     = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            Aspose.Words.Lists.List list = doc.Lists.Add(ListTemplate.NumberDefault);

            // Level 1 labels will be "Appendix A", continuous and linked to the Heading 1 paragraph style.
            list.ListLevels[0].NumberFormat = "Appendix \x0000";
            list.ListLevels[0].NumberStyle  = NumberStyle.UppercaseLetter;
            list.ListLevels[0].LinkedStyle  = doc.Styles["Heading 1"];

            // Level 2 labels will be "Section (1.01)" and restarting after Level 2 item appears.
            list.ListLevels[1].NumberFormat = "Section (\x0000.\x0001)";
            list.ListLevels[1].NumberStyle  = NumberStyle.LeadingZero;
            // Notice the higher level uses UppercaseLetter numbering, but we want arabic number
            // of the higher levels to appear in this level, therefore set this property.
            list.ListLevels[1].IsLegal           = true;
            list.ListLevels[1].RestartAfterLevel = 0;

            // Level 3 labels will be "-I-" and restarting after Level 2 item appears.
            list.ListLevels[2].NumberFormat      = "-\x0002-";
            list.ListLevels[2].NumberStyle       = NumberStyle.UppercaseRoman;
            list.ListLevels[2].RestartAfterLevel = 1;

            // Make labels of all list levels bold.
            foreach (ListLevel level in list.ListLevels)
            {
                level.Font.Bold = true;
            }


            // Apply list formatting to the current paragraph.
            builder.ListFormat.List = list;

            // Exercise the 3 levels we created two times.
            for (int n = 0; n < 2; n++)
            {
                for (int i = 0; i < 3; i++)
                {
                    builder.ListFormat.ListLevelNumber = i;
                    builder.Writeln("Level " + i);
                }
            }

            builder.ListFormat.RemoveNumbers();

            builder.Document.Save(MyDir + @"\Artifacts\Lists.CreateListRestartAfterHigher.doc");
            //ExEnd
        }
Example #13
0
 private static void AddListSample(DocumentBuilder builder, Aspose.Words.Lists.List list)
 {
     builder.Writeln("Sample formatting of list with ListId:" + list.ListId);
     builder.ListFormat.List = list;
     for (int i = 0; i < list.ListLevels.Count; i++)
     {
         builder.ListFormat.ListLevelNumber = i;
         builder.Writeln("Level " + i);
     }
     builder.ListFormat.RemoveNumbers();
     builder.Writeln();
 }
Example #14
0
        //ExEnd

        private void TestOutlineHeadingTemplates(Document doc)
        {
            List list = doc.Lists[0]; // Article section list template

            TestUtil.VerifyListLevel("Article \0.", 0.0d, NumberStyle.UppercaseRoman, list.ListLevels[0]);
            TestUtil.VerifyListLevel("Section \0.\u0001", 0.0d, NumberStyle.LeadingZero, list.ListLevels[1]);
            TestUtil.VerifyListLevel("(\u0002)", 14.4d, NumberStyle.LowercaseLetter, list.ListLevels[2]);
            TestUtil.VerifyListLevel("(\u0003)", 36.0d, NumberStyle.LowercaseRoman, list.ListLevels[3]);
            TestUtil.VerifyListLevel("\u0004)", 28.8d, NumberStyle.Arabic, list.ListLevels[4]);
            TestUtil.VerifyListLevel("\u0005)", 36.0d, NumberStyle.LowercaseLetter, list.ListLevels[5]);
            TestUtil.VerifyListLevel("\u0006)", 50.4d, NumberStyle.LowercaseRoman, list.ListLevels[6]);
            TestUtil.VerifyListLevel("\a.", 50.4d, NumberStyle.LowercaseLetter, list.ListLevels[7]);
            TestUtil.VerifyListLevel("\b.", 72.0d, NumberStyle.LowercaseRoman, list.ListLevels[8]);

            list = doc.Lists[1]; // Legal list template

            TestUtil.VerifyListLevel("\0", 0.0d, NumberStyle.Arabic, list.ListLevels[0]);
            TestUtil.VerifyListLevel("\0.\u0001", 0.0d, NumberStyle.Arabic, list.ListLevels[1]);
            TestUtil.VerifyListLevel("\0.\u0001.\u0002", 0.0d, NumberStyle.Arabic, list.ListLevels[2]);
            TestUtil.VerifyListLevel("\0.\u0001.\u0002.\u0003", 0.0d, NumberStyle.Arabic, list.ListLevels[3]);
            TestUtil.VerifyListLevel("\0.\u0001.\u0002.\u0003.\u0004", 0.0d, NumberStyle.Arabic, list.ListLevels[4]);
            TestUtil.VerifyListLevel("\0.\u0001.\u0002.\u0003.\u0004.\u0005", 0.0d, NumberStyle.Arabic, list.ListLevels[5]);
            TestUtil.VerifyListLevel("\0.\u0001.\u0002.\u0003.\u0004.\u0005.\u0006", 0.0d, NumberStyle.Arabic, list.ListLevels[6]);
            TestUtil.VerifyListLevel("\0.\u0001.\u0002.\u0003.\u0004.\u0005.\u0006.\a", 0.0d, NumberStyle.Arabic, list.ListLevels[7]);
            TestUtil.VerifyListLevel("\0.\u0001.\u0002.\u0003.\u0004.\u0005.\u0006.\a.\b", 0.0d, NumberStyle.Arabic, list.ListLevels[8]);

            list = doc.Lists[2]; // Numbered list template

            TestUtil.VerifyListLevel("\0.", 0.0d, NumberStyle.UppercaseRoman, list.ListLevels[0]);
            TestUtil.VerifyListLevel("\u0001.", 36.0d, NumberStyle.UppercaseLetter, list.ListLevels[1]);
            TestUtil.VerifyListLevel("\u0002.", 72.0d, NumberStyle.Arabic, list.ListLevels[2]);
            TestUtil.VerifyListLevel("\u0003)", 108.0d, NumberStyle.LowercaseLetter, list.ListLevels[3]);
            TestUtil.VerifyListLevel("(\u0004)", 144.0d, NumberStyle.Arabic, list.ListLevels[4]);
            TestUtil.VerifyListLevel("(\u0005)", 180.0d, NumberStyle.LowercaseLetter, list.ListLevels[5]);
            TestUtil.VerifyListLevel("(\u0006)", 216.0d, NumberStyle.LowercaseRoman, list.ListLevels[6]);
            TestUtil.VerifyListLevel("(\a)", 252.0d, NumberStyle.LowercaseLetter, list.ListLevels[7]);
            TestUtil.VerifyListLevel("(\b)", 288.0d, NumberStyle.LowercaseRoman, list.ListLevels[8]);

            list = doc.Lists[3]; // Chapter list template

            TestUtil.VerifyListLevel("Chapter \0", 0.0d, NumberStyle.Arabic, list.ListLevels[0]);
            TestUtil.VerifyListLevel("", 0.0d, NumberStyle.None, list.ListLevels[1]);
            TestUtil.VerifyListLevel("", 0.0d, NumberStyle.None, list.ListLevels[2]);
            TestUtil.VerifyListLevel("", 0.0d, NumberStyle.None, list.ListLevels[3]);
            TestUtil.VerifyListLevel("", 0.0d, NumberStyle.None, list.ListLevels[4]);
            TestUtil.VerifyListLevel("", 0.0d, NumberStyle.None, list.ListLevels[5]);
            TestUtil.VerifyListLevel("", 0.0d, NumberStyle.None, list.ListLevels[6]);
            TestUtil.VerifyListLevel("", 0.0d, NumberStyle.None, list.ListLevels[7]);
            TestUtil.VerifyListLevel("", 0.0d, NumberStyle.None, list.ListLevels[8]);
        }
Example #15
0
        [Test] //ExSkip
        public void PrintOutAllLists()
        {
            Document srcDoc = new Document(MyDir + "Rendering.docx");

            Document        dstDoc  = new Document();
            DocumentBuilder builder = new DocumentBuilder(dstDoc);

            foreach (List srcList in srcDoc.Lists)
            {
                List dstList = dstDoc.Lists.AddCopy(srcList);
                AddListSample(builder, dstList);
            }

            dstDoc.Save(ArtifactsDir + "Lists.PrintOutAllLists.docx");
            TestPrintOutAllLists(srcDoc, new Document(ArtifactsDir + "Lists.PrintOutAllLists.docx")); //ExSkip
        }
Example #16
0
        public void NestedLists()
        {
            //ExStart
            //ExFor:ListFormat.List
            //ExSummary:Shows how to start a numbered list, add a bulleted list inside it, then return to the numbered list.
            Document        doc     = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            // Create an outline list for the headings.
            List outlineList = doc.Lists.Add(ListTemplate.OutlineNumbers);

            builder.ListFormat.List = outlineList;
            builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;
            builder.Writeln("This is my Chapter 1");

            // Create a numbered list.
            List numberedList = doc.Lists.Add(ListTemplate.NumberDefault);

            builder.ListFormat.List = numberedList;
            builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Normal;
            builder.Writeln("Numbered list item 1.");

            // Create a bulleted list.
            List bulletedList = doc.Lists.Add(ListTemplate.BulletDefault);

            builder.ListFormat.List            = bulletedList;
            builder.ParagraphFormat.LeftIndent = 72;
            builder.Writeln("Bulleted list item 1.");
            builder.Writeln("Bulleted list item 2.");
            builder.ParagraphFormat.ClearFormatting();

            // Revert to the numbered list.
            builder.ListFormat.List = numberedList;
            builder.Writeln("Numbered list item 2.");
            builder.Writeln("Numbered list item 3.");

            // Revert to the outline list.
            builder.ListFormat.List = outlineList;
            builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;
            builder.Writeln("This is my Chapter 2");

            builder.ParagraphFormat.ClearFormatting();

            builder.Document.Save(MyDir + @"\Artifacts\Lists.NestedLists.doc");
            //ExEnd
        }
Example #17
0
        private static void AddOutlineHeadingParagraphs(DocumentBuilder builder, Aspose.Words.Lists.List list, string title)
        {
            builder.ParagraphFormat.ClearFormatting();
            builder.Writeln(title);

            for (int i = 0; i < 9; i++)
            {
                builder.ListFormat.List            = list;
                builder.ListFormat.ListLevelNumber = i;

                string styleName = "Heading " + (i + 1).ToString();
                builder.ParagraphFormat.StyleName = styleName;
                builder.Writeln(styleName);
            }

            builder.ListFormat.RemoveNumbers();
        }
Example #18
0
        public void RestartNumberingUsingListCopy()
        {
            //ExStart
            //ExFor:List
            //ExFor:ListCollection
            //ExFor:ListCollection.Add(ListTemplate)
            //ExFor:ListCollection.AddCopy(List)
            //ExFor:ListLevel.StartAt
            //ExFor:ListTemplate
            //ExFor:ListFormat.List
            //ExSummary:Shows how to restart numbering in a list by copying a list.
            Document        doc     = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            // Create a list based on a template.
            List list1 = doc.Lists.Add(ListTemplate.NumberArabicParenthesis);

            // Modify the formatting of the list.
            list1.ListLevels[0].Font.Color = Color.Red;
            list1.ListLevels[0].Alignment  = ListLevelAlignment.Right;

            builder.Writeln("List 1 starts below:");
            // Use the first list in the document for a while.
            builder.ListFormat.List = list1;
            builder.Writeln("Item 1");
            builder.Writeln("Item 2");
            builder.ListFormat.RemoveNumbers();

            // Now I want to reuse the first list, but need to restart numbering.
            // This should be done by creating a copy of the original list formatting.
            List list2 = doc.Lists.AddCopy(list1);

            // We can modify the new list in any way. Including setting new start number.
            list2.ListLevels[0].StartAt = 10;

            // Use the second list in the document.
            builder.Writeln("List 2 starts below:");
            builder.ListFormat.List = list2;
            builder.Writeln("Item 1");
            builder.Writeln("Item 2");
            builder.ListFormat.RemoveNumbers();

            builder.Document.Save(MyDir + @"\Artifacts\Lists.RestartNumberingUsingListCopy.doc");
            //ExEnd
        }
Example #19
0
        //ExStart
        //ExFor:ListCollection
        //ExFor:ListCollection.AddCopy(List)
        //ExFor:ListCollection.GetEnumerator
        //ExSummary:Enumerates through all lists defined in one document and creates a sample of those lists in another document.
        public void PrintOutAllLists()
        {
            // You can use any of your documents to try this little program out.
            Document srcDoc = new Document(MyDir + "Lists.PrintOutAllLists.doc");

            // This will be the sample document we product.
            Document        dstDoc  = new Document();
            DocumentBuilder builder = new DocumentBuilder(dstDoc);

            foreach (Aspose.Words.Lists.List srcList in srcDoc.Lists)
            {
                // This copies the list formatting from the source into the destination document.
                Aspose.Words.Lists.List dstList = dstDoc.Lists.AddCopy(srcList);
                AddListSample(builder, dstList);
            }

            dstDoc.Save(MyDir + @"\Artifacts\Lists.PrintOutAllLists.doc");
        }
Example #20
0
        [Test] //ExSkip
        public void PrintOutAllLists()
        {
            // Open a document that contains lists
            Document srcDoc = new Document(MyDir + "Rendering.docx");

            // This will be the sample document we product
            Document        dstDoc  = new Document();
            DocumentBuilder builder = new DocumentBuilder(dstDoc);

            foreach (List srcList in srcDoc.Lists)
            {
                // This copies the list formatting from the source into the destination document
                List dstList = dstDoc.Lists.AddCopy(srcList);
                AddListSample(builder, dstList);
            }

            dstDoc.Save(ArtifactsDir + "Lists.PrintOutAllLists.docx");
            TestPrintOutAllLists(srcDoc, new Document(ArtifactsDir + "Lists.PrintOutAllLists.docx")); //ExSkip
        }
Example #21
0
        public void ApplyNewListToParagraphs()
        {
            Document doc = new Document();

            //ExStart
            //ExFor:Paragraph.ListFormat
            //ExFor:ListFormat.ListLevelNumber
            //ExFor:ListCollection.Add(ListTemplate)
            //ExSummary:Creates new list formatting and applies it to a collection of paragraphs.
            Aspose.Words.Lists.List list = doc.Lists.Add(ListTemplate.NumberUppercaseLetterDot);

            Body body = doc.FirstSection.Body;

            foreach (Paragraph paragraph in body.Paragraphs)
            {
                paragraph.ListFormat.List            = list;
                paragraph.ListFormat.ListLevelNumber = 1;
            }
            //ExEnd
        }
Example #22
0
        public void ApplyExistingListToParagraphs()
        {
            Aspose.Words.Document doc = new Aspose.Words.Document();
            doc.Lists.Add(ListTemplate.NumberDefault);

            //ExStart
            //ExFor:Paragraph.ListFormat
            //ExFor:ListFormat.List
            //ExFor:ListFormat.ListLevelNumber
            //ExFor:ListCollection.Item(Int32)
            //ExSummary:Applies list formatting of an existing list to a collection of paragraphs.
            Body body = doc.FirstSection.Body;

            Aspose.Words.Lists.List list = doc.Lists[0];
            foreach (Paragraph paragraph in body.Paragraphs)
            {
                paragraph.ListFormat.List            = list;
                paragraph.ListFormat.ListLevelNumber = 2;
            }
            //ExEnd
        }
Example #23
0
        //ExStart
        //ExFor:ListTemplate
        //ExSummary:Creates a sample document that exercises all outline headings list templates.
        public void OutlineHeadingTemplates()
        {
            Document        doc     = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            Aspose.Words.Lists.List list = doc.Lists.Add(ListTemplate.OutlineHeadingsArticleSection);
            AddOutlineHeadingParagraphs(builder, list, "Aspose.Words Outline 1");

            list = doc.Lists.Add(ListTemplate.OutlineHeadingsLegal);
            AddOutlineHeadingParagraphs(builder, list, "Aspose.Words Outline 2");

            builder.InsertBreak(BreakType.PageBreak);

            list = doc.Lists.Add(ListTemplate.OutlineHeadingsNumbers);
            AddOutlineHeadingParagraphs(builder, list, "Aspose.Words Outline 3");

            list = doc.Lists.Add(ListTemplate.OutlineHeadingsChapter);
            AddOutlineHeadingParagraphs(builder, list, "Aspose.Words Outline 4");

            builder.Document.Save(MyDir + @"\Artifacts\Lists.OutlineHeadingTemplates.doc");
        }
Example #24
0
        public static void RestartListNumber(String dataDir)
        {
            // ExStart:RestartListNumber
            Document        doc     = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            // Create a list based on a template.
            Aspose.Words.Lists.List list1 = doc.Lists.Add(ListTemplate.NumberArabicParenthesis);
            // Modify the formatting of the list.
            list1.ListLevels[0].Font.Color = Color.Red;
            list1.ListLevels[0].Alignment  = ListLevelAlignment.Right;

            builder.Writeln("List 1 starts below:");
            // Use the first list in the document for a while.
            builder.ListFormat.List = list1;
            builder.Writeln("Item 1");
            builder.Writeln("Item 2");
            builder.ListFormat.RemoveNumbers();

            // Now I want to reuse the first list, but need to restart numbering.
            // This should be done by creating a copy of the original list formatting.
            Aspose.Words.Lists.List list2 = doc.Lists.AddCopy(list1);

            // We can modify the new list in any way. Including setting new start number.
            list2.ListLevels[0].StartAt = 10;

            // Use the second list in the document.
            builder.Writeln("List 2 starts below:");
            builder.ListFormat.List = list2;
            builder.Writeln("Item 1");
            builder.Writeln("Item 2");
            builder.ListFormat.RemoveNumbers();

            dataDir = dataDir + "Lists.RestartNumberingUsingListCopy Out.doc";

            // Save the document to disk.
            builder.Document.Save(dataDir);
            // ExEnd:RestartListNumber
            Console.WriteLine("\nDocument is saved successfully.\nFile saved at " + dataDir);
        }
        public void RestartingDocumentList()
        {
            //ExStart
            //ExFor:List.IsRestartAtEachSection
            //ExSummary:Shows how to specify that the list has to be restarted at each section.
            Document doc = new Document();

            doc.Lists.Add(ListTemplate.NumberDefault);

            Aspose.Words.Lists.List list = doc.Lists[0];

            // Set true to specify that the list has to be restarted at each section.
            list.IsRestartAtEachSection = true;

            DocumentBuilder builder = new DocumentBuilder(doc);

            builder.ListFormat.List = list;

            for (int i = 1; i <= 45; i++)
            {
                builder.Write($"List Item {i}\n");

                // Insert section break.
                if (i == 15 || i == 30)
                {
                    builder.InsertBreak(BreakType.SectionBreakNewPage);
                }
            }

            // IsRestartAtEachSection will be written only if compliance is higher then OoxmlComplianceCore.Ecma376
            OoxmlSaveOptions options = new OoxmlSaveOptions
            {
                Compliance = OoxmlCompliance.Iso29500_2008_Transitional
            };

            doc.Save(MyDir + @"\Artifacts\RestartingDocumentList.docx", options);
            //ExEnd
        }
Example #26
0
        public void CreatePictureBullet()
        {
            //ExStart
            //ExFor:ListLevel.CreatePictureBullet
            //ExFor:ListLevel.DeletePictureBullet
            //ExSummary:Shows how to creating and deleting picture bullet with custom image.
            Document doc = new Document();

            // Create a list with template
            List list = doc.Lists.Add(ListTemplate.BulletCircle);

            // Create picture bullet for the current list level
            list.ListLevels[0].CreatePictureBullet();

            // Set your own picture bullet image through the ImageData
            list.ListLevels[0].ImageData.SetImage(ImageDir + "Logo icon.ico");

            Assert.IsTrue(list.ListLevels[0].ImageData.HasImage);

            // Create a list, configure its bullets to use our image and add two list items
            DocumentBuilder builder = new DocumentBuilder(doc);

            builder.ListFormat.List = list;
            builder.Writeln("Hello world!");
            builder.Write("Hello again!");

            doc.Save(ArtifactsDir + "Lists.CreatePictureBullet.docx");

            // Delete picture bullet
            list.ListLevels[0].DeletePictureBullet();

            Assert.IsNull(list.ListLevels[0].ImageData);
            //ExEnd

            doc = new Document(ArtifactsDir + "Lists.CreatePictureBullet.docx");

            Assert.IsTrue(doc.Lists[0].ListLevels[0].ImageData.HasImage);
        }
        public void ControlListLabelsExport(ExportListLabels howExportListLabels)
        {
            Document        doc     = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            Aspose.Words.Lists.List bulletedList = doc.Lists.Add(ListTemplate.BulletDefault);
            builder.ListFormat.List            = bulletedList;
            builder.ParagraphFormat.LeftIndent = 72;
            builder.Writeln("Bulleted list item 1.");
            builder.Writeln("Bulleted list item 2.");
            builder.ParagraphFormat.ClearFormatting();

            HtmlSaveOptions saveOptions = new HtmlSaveOptions(SaveFormat.Html)
            {
                // 'ExportListLabels.Auto' - this option uses <ul> and <ol> tags are used for list label representation if it doesn't cause formatting loss,
                // otherwise HTML <p> tag is used. This is also the default value
                // 'ExportListLabels.AsInlineText' - using this option the <p> tag is used for any list label representation
                // 'ExportListLabels.ByHtmlTags' - The <ul> and <ol> tags are used for list label representation. Some formatting loss is possible
                ExportListLabels = howExportListLabels
            };

            doc.Save(ArtifactsDir + $"HtmlSaveOptions.ControlListLabelsExport.html", saveOptions);
        }
        public void PrintOutAllLists()
        {
            //ExStart
            //ExFor:ListCollection
            //ExFor:ListCollection.AddCopy(List)
            //ExFor:ListCollection.GetEnumerator
            //ExSummary:Enumerates through all lists defined in one document and creates a sample of those lists in another document.
            // You can use any of your documents to try this little program out.
            Document srcDoc = new Document(MyDir + "Lists.PrintOutAllLists.doc");

            // This will be the sample document we product.
            Document        dstDoc  = new Document();
            DocumentBuilder builder = new DocumentBuilder(dstDoc);

            foreach (Aspose.Words.Lists.List srcList in srcDoc.Lists)
            {
                // This copies the list formatting from the source into the destination document.
                Aspose.Words.Lists.List dstList = dstDoc.Lists.AddCopy(srcList);
                AddListSample(builder, dstList);
            }

            dstDoc.Save(MyDir + @"\Artifacts\Lists.PrintOutAllLists.doc");
        }
Example #29
0
        [Test] //ExSkip
        public void OutlineHeadingTemplates()
        {
            Document        doc     = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            List list = doc.Lists.Add(ListTemplate.OutlineHeadingsArticleSection);

            AddOutlineHeadingParagraphs(builder, list, "Aspose.Words Outline - \"Article Section\"");

            list = doc.Lists.Add(ListTemplate.OutlineHeadingsLegal);
            AddOutlineHeadingParagraphs(builder, list, "Aspose.Words Outline - \"Legal\"");

            builder.InsertBreak(BreakType.PageBreak);

            list = doc.Lists.Add(ListTemplate.OutlineHeadingsNumbers);
            AddOutlineHeadingParagraphs(builder, list, "Aspose.Words Outline - \"Numbers\"");

            list = doc.Lists.Add(ListTemplate.OutlineHeadingsChapter);
            AddOutlineHeadingParagraphs(builder, list, "Aspose.Words Outline - \"Chapters\"");

            doc.Save(ArtifactsDir + "Lists.OutlineHeadingTemplates.docx");
            TestOutlineHeadingTemplates(new Document(ArtifactsDir + "Lists.OutlineHeadingTemplates.docx")); //ExSkip
        }
        public void RestartingDocumentList(bool restartListAtEachSection)
        {
            //ExStart
            //ExFor:List.IsRestartAtEachSection
            //ExFor:OoxmlCompliance
            //ExFor:OoxmlSaveOptions.Compliance
            //ExSummary:Shows how to configure a list to restart numbering at each section.
            Document        doc     = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            doc.Lists.Add(ListTemplate.NumberDefault);

            Aspose.Words.Lists.List list = doc.Lists[0];
            list.IsRestartAtEachSection = restartListAtEachSection;

            // The "IsRestartAtEachSection" property will only be applicable when
            // the document's OOXML compliance level is to a standard that is newer than "OoxmlComplianceCore.Ecma376".
            OoxmlSaveOptions options = new OoxmlSaveOptions
            {
                Compliance = OoxmlCompliance.Iso29500_2008_Transitional
            };

            builder.ListFormat.List = list;

            builder.Writeln("List item 1");
            builder.Writeln("List item 2");
            builder.InsertBreak(BreakType.SectionBreakNewPage);
            builder.Writeln("List item 3");
            builder.Writeln("List item 4");

            doc.Save(ArtifactsDir + "OoxmlSaveOptions.RestartingDocumentList.docx", options);

            doc = new Document(ArtifactsDir + "OoxmlSaveOptions.RestartingDocumentList.docx");

            Assert.AreEqual(restartListAtEachSection, doc.Lists[0].IsRestartAtEachSection);
            //ExEnd
        }