Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ms word OpenXML跨列拆分表_Ms Word_Openxml - Fatal编程技术网

Ms word OpenXML跨列拆分表

Ms word OpenXML跨列拆分表,ms-word,openxml,Ms Word,Openxml,使用OpenXML,我要做的是在Word文档中插入一个表。这很好,但是现在我需要表格在两个Word列之间断开(如Word中的报纸类型列,而不是表格本身的列)。因此,在Word中,我将我的表,在前面添加了一个分节符,在后面添加了一个分节符,然后将它设置为两列,它将我的表拆分为两列,并将其分布到各个列。查看Open XML productivity tool中的布局,我看到它在表之前添加了以下内容: <w:p w:rsidR="00E634EE" w:rsidRDefault="00E634E

使用OpenXML,我要做的是在Word文档中插入一个表。这很好,但是现在我需要表格在两个Word列之间断开(如Word中的报纸类型列,而不是表格本身的列)。因此,在Word中,我将我的表,在前面添加了一个分节符,在后面添加了一个分节符,然后将它设置为两列,它将我的表拆分为两列,并将其分布到各个列。查看Open XML productivity tool中的布局,我看到它在表之前添加了以下内容:

<w:p w:rsidR="00E634EE" w:rsidRDefault="00E634EE" w14:paraId="0D41C6E2" w14:textId="77777777" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:pPr>
    <w:sectPr w:rsidR="00E634EE" w:rsidSect="00C511F2">
      <w:pgSz w:w="12240" w:h="15840" />
      <w:pgMar w:top="864" w:right="864" w:bottom="1440" w:left="864" w:header="720" w:footer="720" w:gutter="0" />
      <w:cols w:space="720" />
      <w:docGrid w:linePitch="360" />
    </w:sectPr>
  </w:pPr>
</w:p>

其中,
parent
是我要添加表的元素,而
t
是我的
table
元素。

经过一些实验,我相信我现在已经解决了这个问题。诀窍是,添加另一个分段符


我认为问题在于,如果表格后面没有另一个分节符,下一个分节符就在页面的末尾,因此Word将在第一列中列出所有内容,直到它到达页面的末尾。如果页面上有足够的空间,那么整个表将在一列中结束(并且看起来非常不平衡)。因此,诀窍是在表格后面添加另一个(空)段落,通过跨列拆分来强制Word压缩表格。

请添加最小代码来创建repo。另外,涉及到哪个版本的Word?我无法帮助处理XML,但有一个表行属性设置,用于允许行在页面之间断开或不断开。您可以对此进行实验,并检查如何将其转换为XML代码。@RichMichaels您指的是哪个属性?我没看见。调用时有一个子元素,但看起来不是这样。@Cindymister-我添加了一些代码,但整个元素非常大,我认为不完全必要。问题是什么定义了一个表将被拆分到两列的位置?。这不是一个bug,也不是一个不起作用的代码(嗯,有点像)。问题是如何以及在何处指定将这些行放在第1列中,并将这些行放在第1列中2@MattBurland我不知道OpenXML,但我知道单词VBA,有一个选择布尔值。行(1)。AllowBreakAcrossPages=True,在您的场景中,有一个包含多行表的两列页面,将该布尔值设置为True将允许表格内容流向第二列。否则,整个表将移到第二列。
<w:p w:rsidR="00E634EE" w:rsidP="00E634EE" w:rsidRDefault="00E634EE" w14:paraId="15329047" w14:textId="77777777" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:pPr>
    <w:rPr>
      <w:noProof />
    </w:rPr>
    <w:sectPr w:rsidR="00E634EE" w:rsidSect="00E634EE">
      <w:type w:val="continuous" />
      <w:pgSz w:w="12240" w:h="15840" />
      <w:pgMar w:top="864" w:right="864" w:bottom="1440" w:left="864" w:header="720" w:footer="720" w:gutter="0" />
      <w:cols w:space="720" w:num="2" />
      <w:docGrid w:linePitch="360" />
    </w:sectPr>
  </w:pPr>
</w:p>
<w:p w:rsidR="00EA3E62" w:rsidRDefault="003B0473" w14:paraId="6A8C371A" w14:textId="77777777" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:pPr>
    <w:sectPr w:rsidR="00EA3E62">
      <w:pgSz w:w="12240" w:h="15840" />
      <w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="720" w:footer="720" w:gutter="0" />
      <w:cols w:space="720" />
      <w:docGrid w:linePitch="360" />
    </w:sectPr>
  </w:pPr>
</w:p>
<w:tbl xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
    ...
</w:tbl>
<w:p w:rsidR="00EA3E62" w:rsidRDefault="003B0473" w14:paraId="784DE666" w14:textId="77777777" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:pPr>
    <w:sectPr w:rsidR="00EA3E62">
      <w:type w:val="continuous" />
      <w:pgSz w:w="12240" w:h="15840" />
      <w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="720" w:footer="720" w:gutter="0" />
      <w:cols w:space="720" w:num="2" />
    </w:sectPr>
  </w:pPr>
</w:p>
// Insert section breaks
var end = new Paragraph(
    new ParagraphProperties(
        new SectionProperties(
            new SectionType() { Val = SectionMarkValues.Continuous },
            new Columns() { Space = "720", ColumnCount = 2, Separator = true })
        )
    );
parent.InsertAfterSelf(end);
parent.InsertAfterSelf(t);
parent.InsertAfterSelf(new Paragraph(
    new ParagraphProperties(
        new SectionProperties(
            new SectionType() { Val = SectionMarkValues.Continuous })
        )
    )
);