Spire.Doc 13.8.1 现已发布。该版本支持比较两个列表级别是否一致,以及设置或删除图片项目符号。此外,它还调整了 Word 中与列表相关的部分属性和方法。详情如下。
新功能:
- 新增“ListLevel.Equals(ListLevel level)”比较两个列表级别是否一致。
- 支持设置或删除图片项目符号。
// 创建 Document 对象
Document document = new Document();
// 创建列表样式
ListStyle listStyle_1 = document.Styles.Add(ListType.Bulleted, "bulletList");
ListLevelCollection Levels_1 = listStyle_1.ListRef.Levels;
ListLevel L0 = Levels_1[0];
ListLevel L1 = Levels_1[1];
ListLevel L2 = Levels_1[2];
ListStyle listStyle_2 = document.Styles.Add(ListType.Bulleted, "bulletList");
ListLevelCollection Levels_2 = listStyle_2.ListRef.Levels;
ListLevel l0 = Levels_2[0];
ListLevel l1 = Levels_2[1];
ListLevel l2 = Levels_2[2];
// 设置列表样式
L0.ParagraphFormat.LineSpacing = 10 * 1.5f;
L1.CharacterFormat.FontSize = 9;
L1.IsLegalStyleNumbering = true;
L1.PatternType = ListPatternType.Arabic;
L1.FollowCharacter = FollowCharacterType.Nothing;
L1.BulletCharacter = "\x006e";
L1.NumberAlignment = ListNumberAlignment.Left;
L1.NumberPosition = -10;
L1.TabSpaceAfter = 0.5f;
L1.TextPosition = 0.5f;
L1.StartAt = 4;
L1.NumberSufix = "章";
L1.NumberPrefix = "第";
L1.NoRestartByHigher = false;
L1.UsePrevLevelPattern = false;
L2.CharacterFormat.FontName = "黑体";
// 创建列表样式2
l0.ParagraphFormat.LineSpacing = 10 * 1.5f;
l1.CharacterFormat.FontSize = 9;
l1.IsLegalStyleNumbering = true;
l1.PatternType = ListPatternType.Arabic;
l1.FollowCharacter = FollowCharacterType.Nothing;
l1.BulletCharacter = "\x006e";
l1.NumberAlignment = ListNumberAlignment.Left;
l1.NumberPosition = -10;
l1.TabSpaceAfter = 0.5f;
l1.TextPosition = 0.5f;
l1.StartAt = 4;
l1.NumberSufix = "章节";
l1.NumberPrefix = "第";
l1.NoRestartByHigher = false;
l1.UsePrevLevelPattern = false;
l1.CreatePictureBullet();
l2.CharacterFormat.FontName = "黑体";
// 比较两个列表级别是否一致
bool r0 = L0.Equals(l0);
bool r1 = L1.Equals(l1);
bool r2 = L2.Equals(l2);
// 创建 Document 对象
Document document = new Document();
// 添加一节
Section sec = document.AddSection();
Spire.Doc.Documents.Paragraph paragraph = sec.AddParagraph();
// 创建列表样式
ListStyle listStyle = document.Styles.Add(ListType.Bulleted, "bulletList");
ListLevelCollection Levels = listStyle.ListRef.Levels;
Levels[0].CreatePictureBullet();
Levels[0].PictureBullet.LoadImage(@"logo.jpg");
Levels[1].CreatePictureBullet();
Levels[1].PictureBullet.LoadImage(@"py.jpg");
// 添加段落并应用段落样式
paragraph = sec.AddParagraph();
paragraph.AppendText("项目 1");
paragraph.ListFormat.ApplyStyle(listStyle);
paragraph = sec.AddParagraph();
paragraph.AppendText("项目 1.1");
paragraph.ListFormat.ApplyStyle(listStyle);
paragraph.ListFormat.ListLevelNumber = 1;
// 删除图片项目符号
Levels[0].DeletePictureBullet();
// 保存文件
document.SaveToFile(@"out.docx", FileFormat.Docx);
document.Close();
调整:
- 弃用“Document.ListStyles”属性,替换为“Document.ListReferences”。并在“Document.ListReferences”中新加方法创建“ListDefinitionReference”类。
- 回收“ListStyle”的对外公开的构造方法,“ListStyle”对象存放于“Document.Styles”集合中,使用“StyleCollection.Add(ListType listType, string name)”方法添加。
- 段落应用列表样式方式改为“ListFormat.ApplyStyle(ListStyle listStyle)”或“ListFormat.ApplyListRef(ListDefinitionReference list, int leverNumber)”。
- 属性“ListFormat.CurrentListStyle”变更为“ListFormat.CurrentListRef”。
- 回收弃用“ListFormat.IsRestartNumbering”和 “ListFormat.CustomStyleName”。
- 设置列表起始编号的方式更改为:
// 创建 Document 对象
Document document = new Document();
// 添加一节
Section sec = document.AddSection();
Spire.Doc.Documents.Paragraph paragraph = sec.AddParagraph();
// 创建列表模板1
ListTemplate template = ListTemplate.BulletDefault;
ListDefinitionReference listRef = document.ListReferences.Add(template);
// 创建列表模板2
ListTemplate template1 = ListTemplate.NumberDefault;
ListDefinitionReference listRef1 = document.ListReferences.Add(template1);
listRef1.Levels[2].StartAt = 4;
int levelcount = listRef.Levels.Count;
// 添加段落并应用样式
paragraph = sec.AddParagraph();
paragraph.AppendText("项目 1");
paragraph.ListFormat.ApplyListRef(listRef, 1);
paragraph = sec.AddParagraph();
paragraph.AppendText("项目 2");
paragraph.ListFormat.ApplyListRef(listRef, 2);
paragraph = sec.AddParagraph();
paragraph.AppendText("项目3");
paragraph.ListFormat.ApplyListRef(listRef1, 1);
paragraph = sec.AddParagraph();
paragraph.AppendText("项目 4");
paragraph.ListFormat.ApplyListRef(listRef1, 2);
// 保存文件
document.SaveToFile("out.docx", FileFormat.Docx);
document.Close();
ListStyle listStyle = document.Styles.Add(ListType.Numbered, "levelstyle");
listStyle.IsCustomStyle = true;
listStyle.CharacterFormat.FontName = "Trebuchet MS";
ListLevelCollection levels = listStyle.ListRef.Levels;
levels[0].PatternType = ListPatternType.Arabic;
levels[0].StartAt = 1;
levels[0].CharacterFormat.FontName = "Trebuchet MS";
ListStyle numberList2 = document.Styles.Add(ListType.Numbered, "Numbered2");
ListLevelCollection Levels = numberList2.ListRef.Levels;
Levels[0].StartAt = 10;
获取Spire.Doc 13.8.1,请点击: