How to Convert Automatic Numbering to Normal Texts in Word Document

Yeahh, my question is: How to Convert Automatic Numbering to Normal Texts in Word Document
New Microsoft Word Document.docx (49.0 KB)

In my document, I have a numbered list. I want to convert this number list to normal text.
Thank a lot !

@quanghieumylo If you need to convert list numbering into regular text, you can achieve this using code like the following:

Document doc = new Document(@"C:\Temp\in.docx");
           
// Update list labels.
doc.UpdateListLabels();

// Get all paragraphs, which are list items
List<Paragraph> listItems = doc.GetChildNodes(NodeType.Paragraph, true).Cast<Paragraph>()
    .Where(p => p.IsListItem).ToList();

// Convert list items into regular paragraphs with leading text that imitates numbering.
foreach (Paragraph item in listItems )
{
    string label = item.ListLabel.LabelString + "\t";
    Run fakeListLabelRun = new Run(doc, label);
    item.ListFormat.RemoveNumbers();
    item.PrependChild(fakeListLabelRun);
}

doc.Save(@"C:\Temp\out.docx");

Please note before using Paragraph.ListLabel property you should first call Document.UpdateListLabels method.

1 Like

May be it not as well as using VBA in MS word?

Sub ConvertSelectAutoNumberToText()
    If ActiveDocument.Lists.Count > 0 Then
        Selection.Range.ListFormat.ConvertNumbersToText
    Else

    End If
End Sub

@quanghieumylo Unfortunately, there is no built-in method for conversion list labels to text in Aspose.Words API. So the only possible way to achieve this is the code I have proposed in my previous answer.

1 Like

OK, I understand. Thank bro!

1 Like