您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ListSample.cs 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /***************************************************************************************
  2. DocX – DocX is the community edition of Xceed Words for .NET
  3. Copyright (C) 2009-2017 Xceed Software Inc.
  4. This program is provided to you under the terms of the Microsoft Public
  5. License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
  6. For more features and fast professional support,
  7. pick up Xceed Words for .NET at https://xceed.com/xceed-words-for-net/
  8. *************************************************************************************/
  9. using System;
  10. using System.Drawing;
  11. using System.IO;
  12. namespace Xceed.Words.NET.Examples
  13. {
  14. public class ListSample
  15. {
  16. #region Private Members
  17. private const string ListSampleOutputDirectory = Program.SampleDirectory + @"List\Output\";
  18. #endregion
  19. #region Constructors
  20. static ListSample()
  21. {
  22. if( !Directory.Exists( ListSample.ListSampleOutputDirectory ) )
  23. {
  24. Directory.CreateDirectory( ListSample.ListSampleOutputDirectory );
  25. }
  26. }
  27. #endregion
  28. #region Public Methods
  29. /// <summary>
  30. /// Create a numbered and a bulleted lists with different listItem's levels.
  31. /// </summary>
  32. public static void AddList()
  33. {
  34. Console.WriteLine( "\tAddList()" );
  35. // Create a document.
  36. using( DocX document = DocX.Create( ListSample.ListSampleOutputDirectory + @"AddList.docx" ) )
  37. {
  38. // Add a title
  39. document.InsertParagraph( "Adding lists into a document" ).FontSize( 15d ).SpacingAfter( 50d ).Alignment = Alignment.center;
  40. // Add a numbered list where the first ListItem is starting with number 1.
  41. var numberedList = document.AddList( "Berries", 0, ListItemType.Numbered, 1 );
  42. // Add Sub-items(level 1) to the preceding ListItem.
  43. document.AddListItem( numberedList, "Strawberries", 1 );
  44. document.AddListItem( numberedList, "Blueberries", 1 );
  45. document.AddListItem( numberedList, "Raspberries", 1 );
  46. // Add an item (level 0)
  47. document.AddListItem( numberedList, "Banana" );
  48. // Add an item (level 0)
  49. document.AddListItem( numberedList, "Apple" );
  50. // Add Sub-items(level 1) to the preceding ListItem.
  51. document.AddListItem( numberedList, "Red", 1 );
  52. document.AddListItem( numberedList, "Green", 1 );
  53. document.AddListItem( numberedList, "Yellow", 1 );
  54. // Add a bulleted list with its first item.
  55. var bulletedList = document.AddList( "Canada", 0, ListItemType.Bulleted);
  56. // Add Sub-items(level 1) to the preceding ListItem.
  57. document.AddListItem( bulletedList, "Toronto", 1 );
  58. document.AddListItem( bulletedList, "Montreal", 1 );
  59. // Add an item (level 0)
  60. document.AddListItem( bulletedList, "Brazil" );
  61. // Add an item (level 0)
  62. document.AddListItem( bulletedList, "USA" );
  63. // Add Sub-items(level 1) to the preceding ListItem.
  64. document.AddListItem( bulletedList, "New York", 1 );
  65. // Add Sub-items(level 2) to the preceding ListItem.
  66. document.AddListItem( bulletedList, "Brooklyn", 2 );
  67. document.AddListItem( bulletedList, "Manhattan", 2 );
  68. document.AddListItem( bulletedList, "Los Angeles", 1 );
  69. document.AddListItem( bulletedList, "Miami", 1 );
  70. // Add an item (level 0)
  71. document.AddListItem( bulletedList, "France" );
  72. // Add Sub-items(level 1) to the preceding ListItem.
  73. document.AddListItem( bulletedList, "Paris", 1 );
  74. // Insert the lists into the document.
  75. document.InsertParagraph( "This is a Numbered List:\n" );
  76. document.InsertList( numberedList );
  77. document.InsertParagraph().SpacingAfter( 40d );
  78. document.InsertParagraph( "This is a Bulleted List:\n" );
  79. document.InsertList( bulletedList, new Font("Cooper Black"), 15 );
  80. document.Save();
  81. Console.WriteLine( "\tCreated: AddList.docx\n" );
  82. }
  83. }
  84. #endregion
  85. }
  86. }