- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我花了无数时间试图理解 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 中收到兼容模式警告。
有人会过来说:
Use Open XML Productivity Tools and create a doc and look at the generated code
我对此的回应是:
My eyes are bleeding after looking at the 5,000 lines of code a tiny little document to test with creates.
所以我觉得我 super 亲近。我的代码中有很多其他自定义项,这就是为什么我继续引用我开始的地方。如果有人可以举那个例子或提供一个现有的例子,我只想创建多级列表并控制使用的编号类型(lowerRoman、decimal 等)。
更新 1
我真的不得不硬着头皮认真学习。在 Thomas 的帮助下,我得以继续前进,但似乎我还有一个棘手的问题。我的新排序列表不是从“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 Productivity Tools,但我经常使用并推荐 Open XML Package Editor for Modern Visual Studios .使用该包编辑器,您可以查看由 Microsoft Word 创建的 Open XML 标记以从中学习。
因此,为了回答您的问题,我已经这样做了,使用包含多个多级列表的 Word 模板,这些列表的行为与您希望它们的行为完全一样(我希望如此)。
(a) First paragraph, on outline level 0 (shown as 1 in Word)
(b) Second paragraph, on outline level 0
(1) Third paragraph, on outline level 1 (shown as 2 in Word)
(2) Fourth paragraph, on outline level 1
请注意,您通常会在多级列表的不同级别上使用不同的编号格式(例如,小写字母、大写字母、小写罗马字母、大写罗马字母、小数)。
接下来,这是主文档部分对应的 Open XML 标记:
<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:body>
<w:p>
<w:pPr>
<w:pStyle w:val="ListLowerLetter0"/>
</w:pPr>
<w:r>
<w:t>First paragraph, on outline level 0 (shown as 1 in Word)</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:pStyle w:val="ListLowerLetter0"/>
</w:pPr>
<w:r>
<w:t>Second paragraph, on outline level 0</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:pStyle w:val="ListLowerLetter0"/>
<w:numPr>
<w:ilvl w:val="1"/> <!-- This overrides the numbering level -->
<w:numId w:val="43"/> <!-- This references the w:numbering/w:num -->
</w:numPr>
</w:pPr>
<w:r>
<w:t>Third paragraph, on outline level 1 (shown as 2 in Word)</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:pStyle w:val="ListLowerLetter0"/>
<w:numPr>
<w:ilvl w:val="1"/>
<w:numId w:val="43"/>
</w:numPr>
</w:pPr>
<w:r>
<w:t>Fourth paragraph, on outline level 1</w:t>
</w:r>
</w:p>
</w:body>
</w:document>
注意 w:pStyle
和 w:numPr
元素,它们指定要使用的编号段落样式,其中 w:numPr
也使用,覆盖样式中指定的编号默认值。
接下来,这是样式定义部分的 Open XML 标记:
<w:styles xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<!-- This is the paragraph style used in the main document part (w:document) -->
<w:style w:type="paragraph" w:customStyle="1" w:styleId="ListLowerLetter0">
<w:name w:val="List Lower Letter 0"/>
<w:basedOn w:val="Normal"/>
<w:pPr>
<w:numPr>
<w:numId w:val="43"/> <!-- This references the w:numbering/w:num -->
</w:numPr>
</w:pPr>
</w:style>
<!-- This is the list style referenced in the numbering definitions part (w:numbering).
This is optional but helps if you want to use the list in Word. -->
<w:style w:type="numbering" w:customStyle="1" w:styleId="ListLowerLetter0List">
<w:name w:val="List Lower Letter 0 List"/>
<w:basedOn w:val="NoList"/>
<w:pPr>
<w:numPr>
<w:numId w:val="43"/> <!-- This references the w:numbering/w:num -->
</w:numPr>
</w:pPr>
</w:style>
<!-- I've included this for completeness because it is referenced by our
paragraph style below -->
<w:style w:type="paragraph" w:default="1" w:styleId="Normal">
<w:name w:val="Normal"/>
<w:rPr>
<w:kern w:val="16"/>
</w:rPr>
</w:style>
<!-- I've included this for completeness because it is referenced by our
list style below -->
<w:style w:type="numbering" w:default="1" w:styleId="NoList">
<w:name w:val="No List"/>
<w:semiHidden/>
<w:unhideWhenUsed/>
</w:style>
</w:styles>
我真的只需要 ListLowerLetter0
样式。 ListLowerLetter0List
是可选的列表样式。我总是在我的模板中使用它们。其他两种样式只是为了完整性和一致性。显然,现实生活中的样式定义部分包含更多样式和其他元素。
最后,我们有编号定义部分的 Open XML 标记(同样带有解释相关元素作用的注释):
<w:numbering xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
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"
mc:Ignorable="w14 w15">
<!-- Here's an example multi-level list -->
<w:abstractNum w:abstractNumId="67" w15:restartNumberingAfterBreak="0">
<w:nsid w:val="3E434843" />
<w:multiLevelType w:val="multilevel" />
<w:tmpl w:val="1146F302" />
<!-- The w:styleLink references our list style. This is optional (but I use
it as a best practice in Word) -->
<w:styleLink w:val="ListLowerLetter0List" />
<!-- This defines the first outline level, i.e., 0 in Open XML lingo or 1
when you look at it in Word -->
<w:lvl w:ilvl="0">
<!-- This starts the level at the ordinal number 1, i.e., "a" on this level -->
<w:start w:val="1" />
<!-- This defines the number format on this level -->
<w:numFmt w:val="lowerLetter" />
<!-- This references our paragraph style, which will be the same on each level -->
<w:pStyle w:val="ListLowerLetter0" />
<!-- This defines the level text, e.g., (a), (b), (c), ... -->
<w:lvlText w:val="(%1)" />
<!-- The next elements define alignment, indentation, and color -->
<w:lvlJc w:val="left" />
<w:pPr>
<w:ind w:left="851" w:hanging="851" />
</w:pPr>
<w:rPr>
<w:color w:val="auto" />
</w:rPr>
</w:lvl>
<!-- This and the following w:lvl elements define levels 1 to 8 (i.e., 2 to 9 in Word) -->
<w:lvl w:ilvl="1">
<w:start w:val="1" />
<w:numFmt w:val="decimal" />
<w:lvlText w:val="(%2)" />
<w:lvlJc w:val="left" />
<w:pPr>
<w:ind w:left="1418" w:hanging="567" />
</w:pPr>
<w:rPr>
<w:color w:val="auto" />
</w:rPr>
</w:lvl>
<w:lvl w:ilvl="2">
<w:start w:val="1" />
<w:numFmt w:val="upperLetter" />
<w:lvlText w:val="(%3)" />
<w:lvlJc w:val="left" />
<w:pPr>
<w:ind w:left="1985" w:hanging="567" />
</w:pPr>
<w:rPr>
<w:color w:val="auto" />
</w:rPr>
</w:lvl>
<w:lvl w:ilvl="3">
<w:start w:val="1" />
<w:numFmt w:val="lowerRoman" />
<w:lvlText w:val="(%4)" />
<w:lvlJc w:val="left" />
<w:pPr>
<w:ind w:left="2552" w:hanging="567" />
</w:pPr>
<w:rPr>
<w:color w:val="auto" />
</w:rPr>
</w:lvl>
<w:lvl w:ilvl="4">
<w:start w:val="1" />
<w:numFmt w:val="lowerLetter" />
<w:lvlText w:val="%5." />
<w:lvlJc w:val="left" />
<w:pPr>
<w:ind w:left="3119" w:hanging="567" />
</w:pPr>
<w:rPr>
<w:color w:val="auto" />
</w:rPr>
</w:lvl>
<w:lvl w:ilvl="5">
<w:start w:val="1" />
<w:numFmt w:val="decimal" />
<w:lvlText w:val="%6." />
<w:lvlJc w:val="left" />
<w:pPr>
<w:ind w:left="3686" w:hanging="567" />
</w:pPr>
<w:rPr>
<w:color w:val="auto" />
</w:rPr>
</w:lvl>
<w:lvl w:ilvl="6">
<w:start w:val="1" />
<w:numFmt w:val="lowerLetter" />
<w:lvlText w:val="%7." />
<w:lvlJc w:val="left" />
<w:pPr>
<w:ind w:left="4253" w:hanging="567" />
</w:pPr>
<w:rPr>
<w:color w:val="auto" />
</w:rPr>
</w:lvl>
<w:lvl w:ilvl="7">
<w:start w:val="1" />
<w:numFmt w:val="lowerRoman" />
<w:lvlText w:val="%8." />
<w:lvlJc w:val="left" />
<w:pPr>
<w:ind w:left="4820" w:hanging="567" />
</w:pPr>
<w:rPr>
<w:color w:val="auto" />
</w:rPr>
</w:lvl>
<w:lvl w:ilvl="8">
<w:start w:val="1" />
<w:numFmt w:val="lowerLetter" />
<w:lvlText w:val="%9)" />
<w:lvlJc w:val="left" />
<w:pPr>
<w:ind w:left="5387" w:hanging="567" />
</w:pPr>
<w:rPr>
<w:color w:val="auto" />
</w:rPr>
</w:lvl>
</w:abstractNum>
<!-- This is the w:num referenced from our main document part (w:document) -->
<w:num w:numId="43">
<w:abstractNumId w:val="67" />
</w:num>
</w:numbering>
现在,基于对创建所需效果所需标记的理解,使用以下任一方法手写生成该标记的 C# 代码实际上非常容易:
让我为这两个选项提供非常简短的示例,生成以下标记:
<w:num w:numId="43">
<w:abstractNumId w:val="67" />
</w:num>
这是使用 Open XML SDK 的强类型类的代码:
var num = new NumberingInstance
{
NumberID = 43,
AbstractNumId = new AbstractNumId { Val = 67 }
};
这是使用 Open-XML-PowerTools 的代码:
var num =
new XElement(W.num, new XAttribute(W.numId, 43),
new XElement(W.abstractNumId, new XAttribute(W.val, 67)));
在这种情况下,Open-XML-PowerTools 的美妙之处在于您可以按字面意思复制标签名称。此外,Linq to XML 类(例如 XElement
)的构造函数比 Open XML SDK 的构造函数灵活得多,而且 C# 代码看起来很像 Open XML 标记。因此,对于这样的用例,我更倾向于使用 Open-XML-PowerTools。但是,我也非常成功地将 Open XML SDK 用于此类情况。
关于c# - 如何在 ASP.net 中使用 Open XML 创建多级有序列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59093861/
#include using namespace std; class C{ private: int value; public: C(){ value = 0;
这个问题已经有答案了: What is the difference between char a[] = ?string?; and char *p = ?string?;? (8 个回答) 已关闭
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 7 年前。 此帖子已于 8 个月
除了调试之外,是否有任何针对 c、c++ 或 c# 的测试工具,其工作原理类似于将独立函数复制粘贴到某个文本框,然后在其他文本框中输入参数? 最佳答案 也许您会考虑单元测试。我推荐你谷歌测试和谷歌模拟
我想在第二台显示器中移动一个窗口 (HWND)。问题是我尝试了很多方法,例如将分辨率加倍或输入负值,但它永远无法将窗口放在我的第二台显示器上。 关于如何在 C/C++/c# 中执行此操作的任何线索 最
我正在寻找 C/C++/C## 中不同类型 DES 的现有实现。我的运行平台是Windows XP/Vista/7。 我正在尝试编写一个 C# 程序,它将使用 DES 算法进行加密和解密。我需要一些实
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
有没有办法强制将另一个 窗口置于顶部? 不是应用程序的窗口,而是另一个已经在系统上运行的窗口。 (Windows, C/C++/C#) 最佳答案 SetWindowPos(that_window_ha
假设您可以在 C/C++ 或 Csharp 之间做出选择,并且您打算在 Windows 和 Linux 服务器上运行同一服务器的多个实例,那么构建套接字服务器应用程序的最明智选择是什么? 最佳答案 如
你们能告诉我它们之间的区别吗? 顺便问一下,有什么叫C++库或C库的吗? 最佳答案 C++ 标准库 和 C 标准库 是 C++ 和 C 标准定义的库,提供给 C++ 和 C 程序使用。那是那些词的共同
下面的测试代码,我将输出信息放在注释中。我使用的是 gcc 4.8.5 和 Centos 7.2。 #include #include class C { public:
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我的客户将使用名为 annoucement 的结构/类与客户通信。我想我会用 C++ 编写服务器。会有很多不同的类继承annoucement。我的问题是通过网络将这些类发送给客户端 我想也许我应该使用
我在 C# 中有以下函数: public Matrix ConcatDescriptors(IList> descriptors) { int cols = descriptors[0].Co
我有一个项目要编写一个函数来对某些数据执行某些操作。我可以用 C/C++ 编写代码,但我不想与雇主共享该函数的代码。相反,我只想让他有权在他自己的代码中调用该函数。是否可以?我想到了这两种方法 - 在
我使用的是编写糟糕的第 3 方 (C/C++) Api。我从托管代码(C++/CLI)中使用它。有时会出现“访问冲突错误”。这使整个应用程序崩溃。我知道我无法处理这些错误[如果指针访问非法内存位置等,
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,因为
我有一些 C 代码,将使用 P/Invoke 从 C# 调用。我正在尝试为这个 C 函数定义一个 C# 等效项。 SomeData* DoSomething(); struct SomeData {
这个问题已经有答案了: Why are these constructs using pre and post-increment undefined behavior? (14 个回答) 已关闭 6
我是一名优秀的程序员,十分优秀!