Skip to content

Commit 9983cb3

Browse files
committed
Updating the Numbering and Bulleting logic
1 parent 2bf54d3 commit 9983cb3

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

FileFormat.Words/OpenXML.Words.cs

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,13 @@ internal WP.Paragraph CreateParagraph(FF.Paragraph ffP)
148148
var numberingLevelReference = new WP.NumberingLevelReference();
149149

150150
if (ffP.IsBullet)
151-
{
152-
// Assuming '1' is the ID for your bullet list definition in NumberingDefinitionsPart
153-
numberingId.Val = 1; // This value should match the ID of your bullet list definition
154-
numberingLevelReference.Val = ffP.NumberingLevel ?? 0; // Use the specified level or default to 0
151+
{
152+
numberingId.Val = 1;
153+
numberingLevelReference.Val = ffP.NumberingLevel ?? 0;
155154
}
156155
else if (ffP.IsNumbered)
157156
{
158-
numberingId.Val = ffP.NumberingId <= 1 || ffP.NumberingId == null ? 2 : ffP.NumberingId; // This value should match the ID of your numbered list definition, assuming '2' as an example
157+
numberingId.Val = ffP.NumberingId <= 1 || ffP.NumberingId == null ? 2 : ffP.NumberingId;
159158
numberingLevelReference.Val = ffP.NumberingLevel ?? 0;
160159
}
161160

@@ -237,22 +236,14 @@ internal void AddNumberingDefinitions(PKG.WordprocessingDocument pkgDocument)
237236
WP.Numbering numbering = new WP.Numbering();
238237

239238
WP.AbstractNum abstractNumBulleted = new WP.AbstractNum() { AbstractNumberId = 1 };
240-
abstractNumBulleted.Append(new WP.Level(
241-
new WP.NumberingFormat() { Val = WP.NumberFormatValues.Bullet },
242-
new WP.LevelText() { Val = "•" },
243-
new WP.LevelJustification() { Val = WP.LevelJustificationValues.Left }
244-
)
245-
{ LevelIndex = 0 });
246-
247239
WP.AbstractNum abstractNumNumbered = new WP.AbstractNum() { AbstractNumberId = 2 };
248-
abstractNumNumbered.Append(new WP.Level(
249-
new WP.StartNumberingValue() { Val = 1 },
250-
new WP.NumberingFormat() { Val = WP.NumberFormatValues.Decimal },
251-
new WP.LevelText() { Val = "%1." },
252-
new WP.LevelJustification() { Val = WP.LevelJustificationValues.Left }
253-
)
254-
{ LevelIndex = 0 });
255-
240+
241+
for (int i = 0; i < 9; i++)
242+
{
243+
abstractNumBulleted.Append(CreateLevel(i, WP.NumberFormatValues.Bullet, "•"));
244+
abstractNumNumbered.Append(CreateLevel(i, WP.NumberFormatValues.Decimal, $"%{i + 1}."));
245+
}
246+
256247
numbering.Append(abstractNumBulleted);
257248
numbering.Append(abstractNumNumbered);
258249

@@ -268,6 +259,22 @@ internal void AddNumberingDefinitions(PKG.WordprocessingDocument pkgDocument)
268259
numberingPart.Numbering = numbering;
269260
}
270261

262+
private WP.Level CreateLevel(int levelIndex, WP.NumberFormatValues numFormatVal, string levelTextVal)
263+
{
264+
WP.Level level = new WP.Level(
265+
new WP.StartNumberingValue() { Val = 1 },
266+
new WP.NumberingFormat() { Val = numFormatVal },
267+
new WP.LevelText() { Val = levelTextVal },
268+
new WP.LevelJustification() { Val = WP.LevelJustificationValues.Left }
269+
)
270+
{ LevelIndex = levelIndex };
271+
if (numFormatVal == WP.NumberFormatValues.Bullet)
272+
{
273+
level.RemoveAllChildren<WP.StartNumberingValue>();
274+
}
275+
return level;
276+
}
277+
271278
private void SetIndentation(WP.ParagraphProperties paragraphProperties, FF.Indentation ffIndentation)
272279
{
273280
var indentation = new WP.Indentation();

0 commit comments

Comments
 (0)