我花了无数时间试图理解Open XML中的有序列表。这是许多参考文献的one。
我发现这个简单的文档创建者here的非常有用的示例。
同样,如果我可能会有些不适,我必须说这是一个痛苦的学习过程。创建编号属性并引用正确的abstractNumberId
,列表将不断显示。
有人在代码中创建多级列表的完整示例吗?我无需设置NumberFormatValues.Decimal
就可以进行自定义设置。一旦您要开始控制listType
,就会有很多即时开销。
以上面的示例开始,我添加了一个level
参数:
public void AddBulletList(List<Run> runList, int level)
我将其并入此行:
var abstractLevel = new Level(new NumberingFormat() {
Val = NumberFormatValues.Decimal}, new LevelText() {Val = "·"}) {LevelIndex = level};
注意,我将格式类型更改为十进制...方法名称显示为bullet,但我只是在这里进行测试。
我也利用它来处理缩进:
var indentation = new Indentation() { Left = (720 * (level + 1)).ToString(), Hanging = "360" };
因此,在我的测试中,我向传递给0
的级别的方法发送了一些句子。然后,我再发送一些1
作为级别。
我的结果有两个问题:
1)我不知道如何重置计数器,所以我得到了:
1. Sentence 1
2. Sentence 2
3. Sentence 3
4. Sentence 1
5. Sentence 2
6. Sentence 3
我尝试使用levelRestart
,但是没有用:
abstractLevel.LevelRestart = new LevelRestart(){ Val = 0 } // tried 1 also
我唯一可以重新启动的方法是在插入第二个句子列表之前先插入一个空白段落,但这存在样式问题(间距)。
我遇到的第二个问题是编号出现在WordDoc中,但在Microsoft Word中显示为项目符号。此外,我在Microsoft Word中收到兼容模式警告。
有人会过来说:
使用Open XML生产力工具并创建文档并查看生成的代码
我对此的答复是:
[在查看了5,000行代码后,我的眼睛开始流血,这是一个要创建的小文档。
所以我觉得我超级亲密。我的代码中还有许多其他自定义项,这就是为什么我继续参考我的起点的原因。如果有人可以采用该示例或提供现有示例,我只想创建多级列表并控制使用的编号类型(lowerRoman,十进制等)。
更新1
我真的只是硬着头皮做了一些认真的研究。在托马斯的帮助下,我得以继续前进,但看来我还有一个烦人的问题。我的新排序列表不是从“ 1”开始。
注意,在图像中,如果单击第一个列表的级别,它将仅突出显示该列表。我希望它们是分开的,但显然不是。下一个列表应从1开始。
对于每个新的有序列表,我都为其分配了一个新的numberId
,所以我不知道发生了什么。这是生成的标记:
<w:numbering xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex" xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex" xmlns:cx2="http://schemas.microsoft.com/office/drawing/2015/10/21/chartex" xmlns:cx3="http://schemas.microsoft.com/office/drawing/2016/5/9/chartex" xmlns:cx4="http://schemas.microsoft.com/office/drawing/2016/5/10/chartex" xmlns:cx5="http://schemas.microsoft.com/office/drawing/2016/5/11/chartex" xmlns:cx6="http://schemas.microsoft.com/office/drawing/2016/5/12/chartex" xmlns:cx7="http://schemas.microsoft.com/office/drawing/2016/5/13/chartex" xmlns:cx8="http://schemas.microsoft.com/office/drawing/2016/5/14/chartex" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:aink="http://schemas.microsoft.com/office/drawing/2016/ink" xmlns:am3d="http://schemas.microsoft.com/office/drawing/2017/model3d" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w16cid="http://schemas.microsoft.com/office/word/2016/wordml/cid" xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 w15 w16se w16cid wp14"> <w:abstractNum w:abstractNumId="1" w15:restartNumberingAfterBreak="1"> <w:nsid w:val="191025D9" /> <w:multiLevelType w:val="hybridMultilevel" /> <w:tmpl w:val="48A2E570" /> <w:lvl w:ilvl="0" w:tplc="0409000F"> <w:start w:val="1" /> <w:numFmt w:val="decimal" /> <w:lvlText w:val="%1." /> <w:lvlJc w:val="left" /> <w:pPr> <w:ind w:start="720" w:hanging="360" /> </w:pPr> </w:lvl> <w:lvl w:ilvl="1" w:tplc="04090019"> <w:start w:val="1" /> <w:numFmt w:val="lowerLetter" /> <w:lvlText w:val="%2." /> <w:lvlJc w:val="left" /> <w:pPr> <w:ind w:start="1440" w:hanging="360" /> </w:pPr> </w:lvl> </w:abstractNum> <w:abstractNum w:abstractNumId="2" w15:restartNumberingAfterBreak="1"> <w:nsid w:val="191025D9" /> <w:multiLevelType w:val="hybridMultilevel" /> <w:tmpl w:val="48A2E570" /> <w:lvl w:ilvl="0" w:tplc="0409000F"> <w:start w:val="1" /> <w:numFmt w:val="decimal" /> <w:lvlText w:val="%1." /> <w:lvlJc w:val="left" /> <w:pPr> <w:ind w:start="720" w:hanging="360" /> </w:pPr> </w:lvl> <w:lvl w:ilvl="1" w:tplc="04090019"> <w:start w:val="1" /> <w:numFmt w:val="lowerLetter" /> <w:lvlText w:val="%2." /> <w:lvlJc w:val="left" /> <w:pPr> <w:ind w:start="1440" w:hanging="360" /> </w:pPr> </w:lvl> </w:abstractNum> <w:num w:numId="1"> <w:abstractNumId w:val="1" /> </w:num> <w:num w:numId="2"> <w:abstractNumId w:val="2" /> </w:num> </w:numbering>
这里是尸体:
<w:body xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:p>
<w:pPr>
<w:pStyle w:val="ListParagraph" />
<w:numPr>
<w:ilvl w:val="0" />
<w:numId w:val="1" />
</w:numPr>
</w:pPr>
<w:r>
<w:t>List one item 1</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:pStyle w:val="ListParagraph" />
<w:numPr>
<w:ilvl w:val="0" />
<w:numId w:val="1" />
</w:numPr>
</w:pPr>
<w:r>
<w:t>List one item 2</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:pStyle w:val="ListParagraph" />
<w:numPr>
<w:ilvl w:val="0" />
<w:numId w:val="2" />
</w:numPr>
</w:pPr>
<w:r>
<w:t>List two item 1</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:pStyle w:val="ListParagraph" />
<w:numPr>
<w:ilvl w:val="0" />
<w:numId w:val="2" />
</w:numPr>
</w:pPr>
<w:r>
<w:t>List two item 2</w:t>
</w:r>
</w:p>
</w:body>
我花了无数时间试图理解Open XML中的有序列表。这是众多参考文献之一。我在这里找到了一个简单的文档创建者的非常有用的示例。另外,如果我可以...
尽管我从未使用过Open XML生产力工具,但我经常使用并推荐Open XML Package Editor for Modern Visual Studios。使用该程序包编辑器,您可以查看由Microsoft Word创建的Open XML标记,以从中学习。