Skip to content

Commit 41a65e1

Browse files
committed
Bullets and numbering code added here
1 parent 5af745b commit 41a65e1

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

FileFormat.Words/FileFormat.Words.IElements.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,26 @@ public class Paragraph : IElement
5656
/// </summary>
5757
public Indentation Indentation { get; set; }
5858

59+
/// <summary>
60+
/// Gets or sets the numbering ID for the paragraph.
61+
/// </summary>
62+
public int? NumberingId { get; set; }
63+
64+
/// <summary>
65+
/// Gets or sets the numbering level for the paragraph.
66+
/// </summary>
67+
public int? NumberingLevel { get; set; }
68+
69+
/// <summary>
70+
/// Gets or sets whether the paragraph has bullet points.
71+
/// </summary>
72+
public bool IsBullet { get; set; }
73+
74+
/// <summary>
75+
/// Gets or sets whether the paragraph has numbering.
76+
/// </summary>
77+
public bool IsNumbered { get; set; }
78+
5979
/// <summary>
6080
/// Initializes a new instance of the <see cref="Paragraph"/> class.
6181
/// </summary>
@@ -64,6 +84,10 @@ public Paragraph()
6484
Runs = new List<Run>();
6585
Style = "Normal";
6686
Indentation = new Indentation();
87+
NumberingId = null;
88+
NumberingLevel = null;
89+
IsBullet = false;
90+
IsNumbered = false;
6791
UpdateText(); // Initialize the Text property
6892
}
6993

FileFormat.Words/OpenXML.Words.cs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,37 @@ internal WP.Paragraph CreateParagraph(FF.Paragraph ffP)
137137
var paragraphProperties = new WP.ParagraphProperties();
138138
var paragraphStyleId = new WP.ParagraphStyleId { Val = ffP.Style };
139139
paragraphProperties.Append(paragraphStyleId);
140+
140141
if (Enum.TryParse<ParagraphAlignment>(ffP.Alignment, true, out var alignmentEnum))
141142
{
142143
WP.JustificationValues justificationValue = MapAlignmentToJustification(alignmentEnum);
143144
paragraphProperties.Append(new WP.Justification { Val = justificationValue });
144145
}
146+
145147
if (ffP.Indentation != null)
146148
{
147149
SetIndentation(paragraphProperties, ffP.Indentation);
148150
}
151+
152+
if (ffP.IsNumbered)
153+
{
154+
var numberingProperties = new WP.NumberingProperties
155+
{
156+
NumberingId = new WP.NumberingId { Val = ffP.NumberingId },
157+
NumberingLevelReference = new WP.NumberingLevelReference { Val = ffP.NumberingLevel.Value }
158+
};
159+
paragraphProperties.Append(numberingProperties);
160+
}
161+
162+
if (ffP.IsBullet)
163+
{
164+
var bulletProperties = new WP.NumberingProperties
165+
{
166+
NumberingId = new WP.NumberingId { Val = 1 },
167+
NumberingLevelReference = new WP.NumberingLevelReference { Val = 0 }
168+
};
169+
paragraphProperties.Append(bulletProperties);
170+
}
149171
wpParagraph.Append(paragraphProperties);
150172
}
151173

@@ -518,7 +540,19 @@ internal FF.Paragraph LoadParagraph(WP.Paragraph wpPara, int id)
518540
if (paraStyleId != null)
519541
{
520542
if (paraStyleId.Val != null) ffP.Style = paraStyleId.Val.Value;
521-
}
543+
544+
if (IsBulletStyle(paraStyleId.Val.Value))
545+
{
546+
ffP.IsBullet = true;
547+
}
548+
}
549+
var numberingProperties = paraProps.Elements<WP.NumberingProperties>().FirstOrDefault();
550+
if (numberingProperties != null)
551+
{
552+
ffP.IsNumbered = true;
553+
ffP.NumberingId = numberingProperties.NumberingId?.Val ?? 0;
554+
ffP.NumberingLevel = numberingProperties.NumberingLevelReference?.Val ?? 0;
555+
}
522556
}
523557
var justificationElement = paraProps.Elements<WP.Justification>().FirstOrDefault();
524558
if (justificationElement != null)

0 commit comments

Comments
 (0)