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?
@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");
@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");