Hello, I need to reset the start value of a list with a custom style of “ACT Defined Term Number”.
Attached is a sample document SampleNumbering.docx.
For example, I would like the numbering to restart with (a) under the paragraph starting with “Customer Cause”. I’ve looked over the forum and don’t see a good solution to this.
I am using Aspose.Words.for.Java version 14.12.0 and DocumentBuilder to create the document.
Any help is appreciated. Thanks.
Hi Linda,
Document doc = new Document(getMyDir() + “SampleNumbering.docx”);com.aspose.words.List listCopy = null;
for (Paragraph para : (Iterable<Paragraph>)doc.getChildNodes(NodeType.PARAGRAPH, true))
{
if (para.isListItem())
{
if (para.toString(SaveFormat.TEXT).startsWith("any improper use, misuse "))
listCopy = doc.getLists().addCopy(para.getListFormat().getList());<font color="RED"><b>if</b></font> <font color="BLUE"><b>(</b></font>listCopy <font color="BLUE">!</font><font color="BLUE">=</font> <font color="RED"><b>null</b></font><font color="BLUE"><b>)</b></font> para<font color="BLUE"><b>.</b></font>getListFormat<font color="BLUE"><b>(</b></font><font color="BLUE"><b>)</b></font><font color="BLUE"><b>.</b></font>setList<font color="BLUE"><b>(</b></font>listCopy<font color="BLUE"><b>)</b></font><font color="BLUE"><b>;</b></font> <font color="BLUE"><b>}</b></font>
}
doc.save(getMyDir() + “15.8.0.docx”);
The list copy does not seem to work reliably for me. I can get the first paragraph to start at (a) but then the following paras just pick up with the old list values. such as (a) followed by (e).
When I open the Word document and manually right click --> Restart at 1, the only change I see to the underlying document is this where the number property with <w:ilvl w:val=“0”> is added. I opened up the numbering.xml and there were not multiple copies of the ACTDefinedTermNumber list like there are when I try to copy the list.
Is there any way to set this <w:ilvl w:val="0’> via Aspose DocumentBuilder?
<w:p w:rsidR=“00BE03F3” w:rsidRPr=“00BE03F3” w:rsidRDefault=“00BE03F3” w:rsidP=“00E83BB5”>
<w:pPr>
<w:pStyle w:val=“ACTDefinedTermNumber”/>
<w:numPr>
<w:ilvl w:val=“0”/>
<w:numId w:val=“38”/>
</w:numPr>
</w:pPr>
<w:r>
<w:t>correction of a Fa</w:t>
</w:r>
<w:r>
<w:t xml:space=“preserve”>ult; or </w:t>
</w:r>
</w:p>
Hi Linda,
The SampleNumbering.docx is a sample of the current output. I have attached SampleNumbering_fixed.docx as the desired output. Searching for exact text as shown in the code example above is not a good option. I need to be able to restart (same as ‘Restart at a’) the list numbering at each para with a style of “ACT Defined Term Para”, after the initial list has started.
Hi Linda,
Document doc = new Document(getMyDir() + “SampleNumbering.docx”);com.aspose.words.List listCopy = null;
for (Paragraph para : (Iterable<Paragraph>)doc.getChildNodes(NodeType.PARAGRAPH, true)) {
if (para.getParagraphFormat().getStyleName().equals(“ACT Defined Term Para”)) {
listCopy = doc.getLists().addCopy(doc.getLists().get(0));
}
if (para.getParagraphFormat().getStyleName().equals(“ACT Defined Term Number”)) {
if (listCopy != null)
para.getListFormat().setList(listCopy);
}
}doc.save(getMyDir() + “15.10.0.docx”);
Your last reply got me most of the way there. I needed to determine which list to copy since there are multiple lists in my document. The following method worked out very well for me.
private void resetListStart(Document doc) throws Exception {
com.aspose.words.List listCopyDefTermNumber = null;
com.aspose.words.List definedTermNumberList = doc.getStyles().get(“ACT Defined Term Number”).getListFormat().getList();
logger.debug("definedTermNumberList id: " + definedTermNumberList.getListId() + ", style = " + definedTermNumberList.getStyle());
com.aspose.words.List listCopyPart = null;
com.aspose.words.List partList = doc.getStyles().get(“ACT Part”).getListFormat().getList();
logger.debug("partList id: " + partList.getListId() + ", style = " + partList.getStyle());
for (Paragraph para : (Iterable)doc.getChildNodes(NodeType.PARAGRAPH, true)) {
if (para.getParagraphFormat().getStyleName().equals(“ACT Defined Term Para”)) {
listCopyDefTermNumber = doc.getLists().addCopy(definedTermNumberList);
} else if (para.getParagraphFormat().getStyleName().equals(“ACT Defined Term Number”)) {
if (listCopyDefTermNumber != null)
para.getListFormat().setList(listCopyDefTermNumber);
} else if (para.getParagraphFormat().getStyleName().equals(“ACT Schedule”)) {
listCopyPart = doc.getLists().addCopy(partList);
} else if (para.getParagraphFormat().getStyleName().equals(“ACT Part”)) {
if (listCopyPart != null)
para.getListFormat().setList(listCopyPart);
}
}
}
Thanks again for the help!
Hi,