Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.
Fri Dec 27, 2019 6:40 am
I hava created a multi ListStyle follow "https://www.e-iceblue.com/Tutorials/Spire.Doc/Spire.Doc-Program-Guide/Paragraph/How-to-Create-Multi-level-List-Numbering-in-Word-in-C-VB.NET.html",blow is my code,i want to set listLevel2's number format like "1.1" ,"1.2" this pattern,but this code's result is "二.1". i wonder if i can get the result by set this NumberPrefix property? is there any explain to this property?
- Code: Select all
ListStyle listSty2 = new ListStyle(document, ListType.Numbered);
var listLevel0 = listSty2.Levels[0];
listLevel0.UsePrevLevelPattern = true;
listLevel0.NumberPrefix = "第";
listLevel0.NumberSufix = "章";
listLevel0.PatternType = ListPatternType.ChineseCounting;
var listLevel1 = listSty2.Levels[1];
listLevel1.UsePrevLevelPattern = true;
listLevel1.PatternType = ListPatternType.ChineseCounting;
listLevel1.NumberSufix = "";
listLevel1.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
var listLevel2 = listSty2.Levels[3];
listLevel2.UsePrevLevelPattern = false;
listLevel2.PatternType = ListPatternType.Arabic;
listLevel2.NumberPrefix = "\x0000";
listLevel2.NumberSufix = "";
listLevel2.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
-
standheo
-
- Posts: 24
- Joined: Mon Oct 08, 2018 11:13 am
Fri Dec 27, 2019 9:51 am
Hi,
Thanks for your inquiry.
Please set the "IsLegalStyleNumbering" property of the listLevel2 as true, which could fulfill your requirement. And below is my complete code for you.
- Code: Select all
Document document = new Document();
Section section = document.AddSection();
ListStyle listSty2 = new ListStyle(document, ListType.Numbered);
listSty2.Name = "listSty2name";
var listLevel0 = listSty2.Levels[0];
listLevel0.NumberPrefix = "第";
listLevel0.NumberSufix = "章";
listLevel0.PatternType = ListPatternType.ChineseCounting;
var listLevel1 = listSty2.Levels[1];
listLevel1.UsePrevLevelPattern = false;
listLevel1.PatternType = ListPatternType.ChineseCounting;
listLevel1.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
var listLevel2 = listSty2.Levels[2];
listLevel2.UsePrevLevelPattern = false;
listLevel2.PatternType = ListPatternType.Arabic;
listLevel2.NumberPrefix = "\x0000.";
listLevel2.NumberSufix = " ";
//set IsLegalStyleNumbering property as true
listLevel2.IsLegalStyleNumbering = true;
listLevel2.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
document.ListStyles.Add(listSty2);
Paragraph paragraph = section.AddParagraph();
paragraph.AppendText("The first item");
paragraph.ApplyStyle(BuiltinStyle.Heading1);
paragraph.ListFormat.ListLevelNumber = 0;
paragraph.ListFormat.ApplyStyle("listSty2name");
paragraph = section.AddParagraph();
paragraph.AppendText("The second item");
paragraph.ApplyStyle(BuiltinStyle.Heading1);
paragraph.ListFormat.ListLevelNumber = 1;
paragraph.ListFormat.ApplyStyle("listSty2name");
paragraph = section.AddParagraph();
paragraph.AppendText("The first sub-item");
paragraph.ApplyStyle(BuiltinStyle.Heading2);
paragraph.ListFormat.ListLevelNumber = 2;
paragraph.ListFormat.ApplyStyle("listSty2name");
paragraph = section.AddParagraph();
paragraph.AppendText("The second sub-item");
paragraph.ApplyStyle(BuiltinStyle.Heading2);
paragraph.ListFormat.ContinueListNumbering();
paragraph.ListFormat.ApplyStyle("listSty2name");
document.SaveToFile("result.docx", FileFormat.Docx2013);
Best wishes,
Amber
E-iceblue support team
-
Amber.Gu
-
- Posts: 525
- Joined: Tue Jun 04, 2019 3:16 am
Tue Dec 31, 2019 12:57 am
it works,thank you!
-
standheo
-
- Posts: 24
- Joined: Mon Oct 08, 2018 11:13 am
Tue Dec 31, 2019 1:14 am
Hi,
Thanks for your feedback.
Any question, welcome to contact us. Have a nice day.
Best wishes,
Amber
E-iceblue support team
-
Amber.Gu
-
- Posts: 525
- Joined: Tue Jun 04, 2019 3:16 am