Fix transcript DOCX line numbering starting at 2 (docGrid)
- Disable document grid (w:type='none') when enabling line numbering - Prevents Word from treating an empty grid line as line 1
This commit is contained in:
@@ -327,9 +327,15 @@ def _configure_section_margins(doc, margin=1.0):
|
|||||||
def _enable_line_numbering(section, start_at=1, count_by=1, restart=True):
|
def _enable_line_numbering(section, start_at=1, count_by=1, restart=True):
|
||||||
"""
|
"""
|
||||||
Enable line numbering for a specific section.
|
Enable line numbering for a specific section.
|
||||||
|
Disables the document grid so Word counts lines based on content, not grid lines.
|
||||||
"""
|
"""
|
||||||
sectPr = section._sectPr
|
sectPr = section._sectPr
|
||||||
|
|
||||||
|
# Disable document grid to avoid Word treating a grid line as line 1
|
||||||
|
docGrid = sectPr.find(qn("w:docGrid"))
|
||||||
|
if docGrid is not None:
|
||||||
|
docGrid.set(qn("w:type"), "none")
|
||||||
|
|
||||||
# Create the line numbering element: <w:lnNumType>
|
# Create the line numbering element: <w:lnNumType>
|
||||||
lnNumType = OxmlElement("w:lnNumType")
|
lnNumType = OxmlElement("w:lnNumType")
|
||||||
lnNumType.set(qn("w:start"), str(start_at))
|
lnNumType.set(qn("w:start"), str(start_at))
|
||||||
|
|||||||
Reference in New Issue
Block a user