I use two methods to get the list style of the document
1、The method you recommend:but error:throw Message:The list is a definition of a list style.this is code:
Aspose.Words.Lists.List NewList1;
try
{
doca = new Aspose.Words.Document("wina.docx");
Aspose.Words.Style style = doca.Styles["li2108"];
NewList1 = style.List;
foreach (Aspose.Words.Paragraph p in doca.FirstSection.Body.Paragraphs)
{
if (p.Range.Text.Contains("一"))
{
p.ListFormat.List = NewList1;
p.ListFormat.ListLevelNumber = 0;
}
}
doca.Save("wina2108.docx");
}
catch (Exception ee)
{
throw ee;
}
2、My original method,successful,but I opened the file and got it doca.Lists.Count is 21,and the name is li2108 list style,there are four, not one,doca.lists[20].Style.Name,doca.lists[19].Style.Name,doca.lists[18].Style.Name,doca.lists[17].Style.Name,Their names are li208,this code:
Aspose.Words.Lists.List NewList1;
try
{
doca = new Aspose.Words.Document("wina.docx");
Aspose.Words.Style style = doca.Styles["li2108"];
NewList1 = style.List;
foreach (Aspose.Words.Paragraph p in doca.FirstSection.Body.Paragraphs)
{
if (p.Range.Text.Contains("一"))
{
p.ListFormat.List = NewList1;
p.ListFormat.ListLevelNumber = 0;
// Message "The list is a definition of a list style.
}
}
doca.Save("wina2108.docx");
}
catch (Exception ee)
{
throw ee;
}
I upload two files, one is the source file(wina), one is the target file(Target-wina)
Target-wina.docx (20.1 KB)
wina.docx (20.0 KB)