Converting Word Lists to Text

Hello,

I am trying to mimic the following VBA code using Aspose:
ConvertNumbersToText Method | Microsoft Learn

This word vba method (ActiveDocument.ConvertNumbersToText) converts all auto-numbering to text in a document. For example, in word when you have an auto-numbered list (1,2,3 or a,b,c or i,ii,iii), the list is not actually text and do not exist as text within the word xml files. They seem to be rendered by the word application when a user opens the document inside the word application itself.

I am looking to convert all these auto-numbered lists to text and then resave the word document similar to the vba script.

Does anyone know how I could accomplish this using the Aspose sweet with python?

Regards,
SM

@ln22 You can use the following code to convert list labels to regular text:

doc = aw.Document("C:\\Temp\\in.docx");
           
# Update list labels.
doc.update_list_labels()

# Convert list items into regular paragraphs with leading text that imitates numbering.
for p in doc.get_child_nodes(aw.NodeType.PARAGRAPH, True) :
    para = p.as_paragraph()
    if para.is_list_item :
        label = para.list_label.label_string + "\t";
        fakeListLabelRun = aw.Run(doc, label)
        para.list_format.remove_numbers()
        para.prepend_child(fakeListLabelRun)

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

Hello,

This code worked great. I have a Aspose.Total for .NET license. Can I also use Aspose.Total for Python via .NET with this same license?

Regards,
SM

@ln22 No, Aspose.Words for .NET and Aspose.Words for Python via .NET are different products and require different licenses.

Hello Alexey,

This removes all left indentation for all lists. Is there a way to fix this code to keep indentation intact?

Regards,
SM

@ln22 You can modify the code like this to preserve indents:

doc = aw.Document("C:\\Temp\\in.docx");
           
# Update list labels.
doc.update_list_labels()

# Convert list items into regular paragraphs with leading text that imitates numbering.
for p in doc.get_child_nodes(aw.NodeType.PARAGRAPH, True) :
    para = p.as_paragraph()
    if para.is_list_item :
        label = para.list_label.label_string + "\t";
        fakeListLabelRun = aw.Run(doc, label)
        indent = para.list_format.list_level.number_position
        para.list_format.remove_numbers()
        para.prepend_child(fakeListLabelRun)
        para.paragraph_format.left_indent = indent

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