Skip to content

Commit 6384169

Browse files
Publish lists category examples (#234)
1 parent 73cb778 commit 6384169

33 files changed

Lines changed: 661 additions & 635 deletions

File tree

lists/AGENTS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ Use the simplest workflow that satisfies the task.
213213
## Build and run contract
214214

215215
- Target framework: `net8.0`
216-
- Package: `Aspose.Words` `26.7.0`
216+
- Package: `Aspose.Words` `26.8.0`
217217

218218
## Command reference
219219

@@ -227,7 +227,7 @@ cd ExampleProject
227227
### Add required packages
228228

229229
```bash
230-
dotnet add package Aspose.Words --version 26.7.0
230+
dotnet add package Aspose.Words --version 26.8.0
231231
```
232232

233233
### Copy a category example into the temp project

lists/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Lists Examples for Aspose.Words for .NET
22

3-
This folder contains the live, publish-ready C# examples for the Lists category. Each file is a standalone console example selected from the verified 26.7.0 run.
3+
This folder contains the live, publish-ready C# examples for the Lists category. Each file is a standalone console example selected from the verified 26.8.0 run.
44

55
## Snapshot
66

77
- Category: Lists
88
- Slug: lists
99
- Total examples: 30
1010
- Publish-ready successful examples: 30 / 30
11-
- Source run: 20260802_190455_803b68
11+
- Source run: 20260830_195242_46e1a9
1212
- Numbered List Workflow examples: 2
1313
- Bulleted List Workflow examples: 1
1414
- Nested List Workflow examples: 17
@@ -31,7 +31,7 @@ This folder contains the live, publish-ready C# examples for the Lists category.
3131
## Prerequisites
3232

3333
- .NET SDK 8.0 or later
34-
- Aspose.Words 26.7.0
34+
- Aspose.Words 26.8.0
3535

3636
## Running Examples
3737

@@ -40,7 +40,7 @@ Each file in this folder is a single, standalone `.cs` console example. To run o
4040
```bash
4141
dotnet new console -n ExampleProject --framework net8.0
4242
cd ExampleProject
43-
dotnet add package Aspose.Words --version 26.7.0
43+
dotnet add package Aspose.Words --version 26.8.0
4444

4545
# Copy one example from this folder into the project as Program.cs
4646
# PowerShell:
@@ -61,7 +61,7 @@ Example:
6161
# From the repository root
6262
dotnet new console -n ExampleProject --framework net8.0
6363
cd ExampleProject
64-
dotnet add package Aspose.Words --version 26.7.0
64+
dotnet add package Aspose.Words --version 26.8.0
6565

6666
# PowerShell example
6767
Copy-Item ..\lists\create-a-default-numbered-list-in-a-word-document-using-documentbuilder-listformat-applynu.cs .\Program.cs
@@ -138,6 +138,6 @@ dotnet run --configuration Release --no-build
138138
139139
## Notes for maintainers
140140

141-
- This category is 100% publish-ready for the 26.7.0 run.
141+
- This category is 100% publish-ready for the 26.8.0 run.
142142
- Preserve file-to-task traceability when updating this folder.
143143
- Keep examples standalone and bootstrap local inputs inside the example whenever external sources are mentioned.

lists/add-a-new-list-to-the-document-s-listcollection-and-assign-it-to-multiple-paragraphs-to-sh.cs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,31 @@ public class Program
66
{
77
public static void Main()
88
{
9-
// Create a new blank document.
9+
// Create a new empty document.
1010
Document doc = new Document();
1111
DocumentBuilder builder = new DocumentBuilder(doc);
1212

1313
// Add a new list to the document's ListCollection using a predefined template.
1414
List sharedList = doc.Lists.Add(ListTemplate.BulletDefault);
1515

16-
// Apply the same list to multiple paragraphs.
17-
builder.ListFormat.List = sharedList;
18-
builder.ListFormat.ListLevelNumber = 0; // Use the first level of the list.
16+
// Write a normal paragraph (no list formatting).
17+
builder.Writeln("Paragraph without list.");
1918

20-
builder.Writeln("First shared list item");
21-
builder.Writeln("Second shared list item");
22-
builder.Writeln("Third shared list item");
19+
// Add several paragraphs that share the same list formatting.
20+
for (int i = 1; i <= 3; i++)
21+
{
22+
// Assign the shared list to the current paragraph.
23+
builder.ListFormat.List = sharedList;
24+
// Use the first level of the list (level 0).
25+
builder.ListFormat.ListLevelNumber = 0;
26+
builder.Writeln($"List item {i}");
27+
}
2328

24-
// Stop list formatting for any following paragraphs.
25-
builder.ListFormat.RemoveNumbers();
29+
// Stop applying list formatting for any following paragraphs.
30+
builder.ListFormat.List = null;
31+
builder.Writeln("Paragraph after list.");
2632

27-
// Add a regular paragraph without list formatting.
28-
builder.Writeln("A normal paragraph without list formatting.");
29-
30-
// Save the document to disk.
33+
// Save the document to a file in the current directory.
3134
doc.Save("SharedListExample.docx");
3235
}
3336
}

lists/adjust-listlevel-indentation-by-setting-listlevel-indentation-to-36-points-for-proper-alig.cs

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,39 @@ public class Program
77
{
88
public static void Main()
99
{
10-
// Create a new empty document.
10+
// Create a new blank document.
1111
Document doc = new Document();
12-
13-
// Create a DocumentBuilder to insert content.
1412
DocumentBuilder builder = new DocumentBuilder(doc);
1513

16-
// Add a multi‑level list based on the built‑in NumberDefault template.
14+
// Add a list based on the default numbered template.
1715
List list = doc.Lists.Add(ListTemplate.NumberDefault);
1816

19-
// Adjust the indentation of each list level to 36 points (0.5 inch).
17+
// Adjust the indentation of the first two list levels to 36 points.
2018
// The ListLevel class does not have an Indentation property.
21-
// Instead, set NumberPosition, TextPosition and TabPosition to control the left indent.
22-
foreach (ListLevel level in list.ListLevels)
23-
{
24-
level.NumberPosition = 36.0; // Position of the number/bullet.
25-
level.TextPosition = 36.0; // Position where the text starts.
26-
level.TabPosition = 36.0; // Tab stop for the level.
27-
}
19+
// Use NumberPosition (position of the bullet/number) and TextPosition (position of the text)
20+
// to achieve the desired left indent.
21+
ListLevel level0 = list.ListLevels[0];
22+
level0.NumberPosition = 36; // points
23+
level0.TextPosition = 36; // points
24+
25+
ListLevel level1 = list.ListLevels[1];
26+
level1.NumberPosition = 36; // points
27+
level1.TextPosition = 36; // points
2828

29-
// Apply the list to the builder and add a few items.
29+
// Apply the list to some paragraphs.
3030
builder.ListFormat.List = list;
31-
builder.Writeln("First level item");
32-
builder.ListFormat.ListIndent(); // Move to second level.
33-
builder.Writeln("Second level item");
34-
builder.ListFormat.ListIndent(); // Move to third level.
35-
builder.Writeln("Third level item");
36-
builder.ListFormat.ListOutdent(); // Back to second level.
37-
builder.Writeln("Another second level item");
38-
builder.ListFormat.RemoveNumbers(); // End the list.
31+
builder.Writeln("Item 1");
32+
builder.ListFormat.ListIndent();
33+
builder.Writeln("Subitem 1");
34+
builder.ListFormat.ListOutdent();
35+
builder.Writeln("Item 2");
36+
builder.ListFormat.RemoveNumbers();
3937

4038
// Ensure the output directory exists.
4139
string artifactsDir = Path.Combine(Environment.CurrentDirectory, "Artifacts");
4240
Directory.CreateDirectory(artifactsDir);
4341

4442
// Save the document.
45-
string outputPath = Path.Combine(artifactsDir, "Lists.AdjustIndentation.docx");
46-
doc.Save(outputPath);
43+
doc.Save(Path.Combine(artifactsDir, "AdjustedListIndentation.docx"));
4744
}
4845
}
Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,44 @@
11
using System;
2-
using System.IO;
32
using Aspose.Words;
43
using Aspose.Words.Lists;
4+
using System.Drawing;
55

66
public class Program
77
{
88
public static void Main()
99
{
10-
// Create a new blank document.
10+
// Create a new empty document.
1111
Document doc = new Document();
1212

13-
// Initialize a DocumentBuilder which will be used to insert content.
14-
DocumentBuilder builder = new DocumentBuilder(doc);
15-
1613
// Create a new list based on the default bullet template.
1714
List bulletList = doc.Lists.Add(ListTemplate.BulletDefault);
1815

1916
// Access the first (top) level of the list.
2017
ListLevel level = bulletList.ListLevels[0];
2118

22-
// Set the list level to use a bullet style.
19+
// Set the level to use a bullet style.
2320
level.NumberStyle = NumberStyle.Bullet;
2421

25-
// Define a custom bullet character (black circle in this case).
26-
// The NumberFormat property holds the character that will be displayed as the bullet.
27-
level.NumberFormat = "\u25CF"; // Unicode character: ●
22+
// Define a custom bullet character (★ - black star).
23+
level.NumberFormat = "\u2605";
2824

29-
// Optionally, set the font that contains the bullet glyph.
30-
level.Font.Name = "Symbol";
25+
// Optional: customize the appearance of the bullet.
26+
level.Font.Name = "Arial";
27+
level.Font.Size = 12;
28+
level.Font.Color = Color.DarkBlue;
3129

32-
// Apply the custom list to the builder.
30+
// Use a DocumentBuilder to add paragraphs that will use the custom bullet list.
31+
DocumentBuilder builder = new DocumentBuilder(doc);
3332
builder.ListFormat.List = bulletList;
3433

35-
// Add some list items.
36-
builder.Writeln("First custom bullet item");
37-
builder.Writeln("Second custom bullet item");
38-
builder.Writeln("Third custom bullet item");
34+
builder.Writeln("First item with a custom bullet.");
35+
builder.Writeln("Second item with a custom bullet.");
36+
builder.Writeln("Third item with a custom bullet.");
3937

40-
// End the list.
38+
// End the list formatting.
4139
builder.ListFormat.RemoveNumbers();
4240

43-
// Save the document to the current directory.
44-
string outputPath = Path.Combine(Directory.GetCurrentDirectory(), "CustomBulletList.docx");
45-
doc.Save(outputPath);
41+
// Save the document to a file.
42+
doc.Save("CustomBulletList.docx");
4643
}
4744
}

lists/apply-a-custom-tab-stop-to-list-levels-to-align-text-after-numbers-using-listlevel-tabposi.cs

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,48 @@ public static void Main()
88
{
99
// Create a new blank document.
1010
Document doc = new Document();
11+
DocumentBuilder builder = new DocumentBuilder(doc);
1112

1213
// Add a numbered list based on the default template.
1314
List list = doc.Lists.Add(ListTemplate.NumberDefault);
1415

1516
// Configure the first list level.
16-
ListLevel level = list.ListLevels[0];
17-
level.Font.Size = 12; // Font size for the number.
18-
level.NumberStyle = NumberStyle.Arabic; // Use Arabic numbers.
19-
level.NumberFormat = "%1."; // Number format (e.g., "1.").
20-
level.TrailingCharacter = ListTrailingCharacter.Tab; // Place a tab after the number.
21-
level.NumberPosition = -18; // Position of the number (negative moves it left).
22-
level.TextPosition = 36; // Position where the text starts.
23-
level.TabPosition = 36; // Tab stop aligns the text after the number.
24-
25-
// Use DocumentBuilder to add list items.
26-
DocumentBuilder builder = new DocumentBuilder(doc);
17+
ListLevel level0 = list.ListLevels[0];
18+
level0.Font.Color = System.Drawing.Color.DarkBlue;
19+
level0.Font.Size = 12;
20+
level0.NumberStyle = NumberStyle.Arabic;
21+
level0.NumberFormat = "%1.";
22+
level0.StartAt = 1;
23+
24+
// Position of the number (negative moves it left of the left indent).
25+
level0.NumberPosition = -18; // points
26+
// Position where the text of the paragraph starts.
27+
level0.TextPosition = 36; // points
28+
// Set a tab stop after the number so that the text aligns after the tab.
29+
level0.TabPosition = 36; // points
30+
// Use a tab character as the separator between number and text.
31+
level0.TrailingCharacter = ListTrailingCharacter.Tab;
32+
33+
// Apply the list to subsequent paragraphs.
2734
builder.ListFormat.List = list;
28-
builder.Writeln("First item");
29-
builder.Writeln("Second item");
30-
builder.Writeln("Third item");
31-
builder.ListFormat.RemoveNumbers(); // End the list.
3235

33-
// Save the document to a file.
34-
doc.Save("CustomTabStopList.docx");
36+
// First level items.
37+
builder.Writeln("First level item 1");
38+
builder.Writeln("First level item 2");
39+
40+
// Increase list level (second level).
41+
builder.ListFormat.ListIndent();
42+
builder.Writeln("Second level item 1");
43+
builder.Writeln("Second level item 2");
44+
45+
// Decrease back to first level.
46+
builder.ListFormat.ListOutdent();
47+
builder.Writeln("First level item 3");
48+
49+
// Remove list formatting.
50+
builder.ListFormat.RemoveNumbers();
51+
52+
// Save the document to disk.
53+
doc.Save("CustomTabList.docx");
3554
}
3655
}
Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,35 @@
11
using System;
22
using System.IO;
33
using Aspose.Words;
4-
using Aspose.Words.Lists;
54

6-
namespace AsposeWordsListsExample
5+
public class Program
76
{
8-
public class Program
7+
public static void Main()
98
{
10-
public static void Main()
11-
{
12-
// Create a new blank document.
13-
Document doc = new Document();
9+
// Create a new blank document.
10+
Document doc = new Document();
1411

15-
// Attach a DocumentBuilder to the document.
16-
DocumentBuilder builder = new DocumentBuilder(doc);
12+
// Attach a DocumentBuilder to the document.
13+
DocumentBuilder builder = new DocumentBuilder(doc);
1714

18-
// Write a heading before the list.
19-
builder.Writeln("Default bulleted list example:");
15+
// Write a heading before the list.
16+
builder.Writeln("Aspose.Words main advantages are:");
2017

21-
// Start a default bulleted list and apply it to subsequent paragraphs.
22-
builder.ListFormat.ApplyBulletDefault();
18+
// Start a default bulleted list.
19+
builder.ListFormat.ApplyBulletDefault();
2320

24-
// Add several list items.
25-
builder.Writeln("First bullet item");
26-
builder.Writeln("Second bullet item");
27-
builder.Writeln("Third bullet item");
28-
builder.Writeln("Fourth bullet item");
29-
builder.Writeln("Fifth bullet item");
21+
// Add list items that will be formatted with bullets.
22+
builder.Writeln("High performance");
23+
builder.Writeln("Robust API");
24+
builder.Writeln("Cross‑platform support");
25+
builder.Writeln("Extensive format conversion");
26+
builder.Writeln("Easy to use");
3027

31-
// End the list.
32-
builder.ListFormat.RemoveNumbers();
28+
// End the bulleted list.
29+
builder.ListFormat.RemoveNumbers();
3330

34-
// Define the output folder and file name.
35-
string outputDir = Path.Combine(Environment.CurrentDirectory, "Output");
36-
Directory.CreateDirectory(outputDir);
37-
string outputPath = Path.Combine(outputDir, "DefaultBulletedList.docx");
38-
39-
// Save the document to the specified path.
40-
doc.Save(outputPath);
41-
}
31+
// Save the document to the current working directory.
32+
string outputPath = Path.Combine(Environment.CurrentDirectory, "DefaultBulletedList.docx");
33+
doc.Save(outputPath);
4234
}
4335
}

0 commit comments

Comments
 (0)