简体   繁体   English

有没有办法在 OpenXml C# 中并排放置 2 个段落?

[英]Is the a way to have 2 paragraphs side by side in OpenXml C#?

I am trying to create an OpenXml word document that looks as follows:我正在尝试创建一个如下所示的 OpenXml word 文档:

2.1.1 This is a paragraph 2.1.1 这是一段

2.1.2 This is also a paragraph 2.1.2 这也是一段

2.1.2.1 This paragraph relates to 2.1.2 2.1.2.1 本段与 2.1.2 相关

The initial plan is to have the number in its own paragraph, and have the text in its own paragraph as well but the problem is that there a line breaks the interfere with the structure of the list items.最初的计划是将数字放在自己的段落中,并将文本也放在自己的段落中,但问题是换行符会干扰列表项的结构。

I have tried using OpenXml numbering part but the problem there is that I couldn't figure out how to write custom numbers for the numbering.我曾尝试使用 OpenXml 编号部分,但问题是我无法弄清楚如何为编号编写自定义数字。

I have tried to use Justification and Indentation classes but I can't seem to get the desired result, due to the line breaks that come with each paragraph causing the paragraphs to print one below the other.我曾尝试使用 Justification 和 Indentation 类,但我似乎无法获得所需的结果,因为每个段落附带的换行符导致段落打印在另一个下方。

Is there an alternative way to achieve this result or a way to remove the line breaks for a paragraph?是否有其他方法可以实现此结果或删除段落换行符的方法?

Apologies for not being clear enough when posting the question, but for those who are interested I have managed to solve the problem as follows.很抱歉在发布问题时不够清楚,但对于那些有兴趣的人,我设法解决了以下问题。

  1. I downloaded OpenXml Productivity tools which as available here我下载了 OpenXml 生产力工具,可 在此处获得
  2. I then created the paragraphs that I wanted in MS Word, which looks like this然后我在 MS Word 中创建了我想要的段落,看起来像这样
  3. I then used the tool to generate the code needed, and here it is.`然后我使用该工具生成所需的代码,它就在这里。`

     Paragraph paragraph1 = new Paragraph(){ RsidParagraphAddition = "005C6DC7", RsidParagraphProperties = "005C6DC7", RsidRunAdditionDefault = "005C6DC7", ParagraphId = "5F7449EC", TextId = "6B3C1D9C" };段落paragraph1 = new Paragraph(){ RsidParagraphAddition = "005C6DC7", RsidParagraphProperties = "005C6DC7", RsidRunAdditionDefault = "005C6DC7", ParagraphId = "5F7449EC", TextId = "6B3C1D9C" };

    \n\n Run run1 = new Run(); Text text1 = new Text(); text1.Text = "2.1.2"; run1.Append(text1); Run run2 = new Run(); TabChar tabChar1 = new TabChar(); Text text2 = new Text(); text2.Text = "More text"; run2.Append(tabChar1); run2.Append(text2); paragraph1.Append(run1); paragraph1.Append(run2); return paragraph1;`

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM