简体   繁体   English

Python-Docx 列

[英]Python-Docx Columns

I am trying to format a piece of text into columns.我正在尝试将一段文本格式化为列。 There are two aspects that I am trying to achieve:我试图实现两个方面:

  1. I am trying to have multiple sections within a page.我试图在一个页面中有多个部分。 The first paragraph to have only one column layout and the rest of the paragraph to be formatted as two column text.第一个段落只有一个列布局,段落的其余部分被格式化为两列文本。 I have tried creating different sections, then add paragraph and then create another section with two column layout, but no success.我尝试创建不同的部分,然后添加段落,然后创建具有两列布局的另一个部分,但没有成功。 I am ending up messing up layouts.我最终搞砸了布局。

    1. When I create two column layouts, the second column is getting populated with text only after first column is fully populated.当我创建两列布局时,只有在第一列完全填充后,第二列才会填充文本。 This means, if the text is only long enough to populate first column, I am getting a blank second row, instead of auto adjusting the length to split it into 2 columns easily.Is there a way to achieve that?这意味着,如果文本的长度仅足以填充第一列,我会得到一个空白的第二行,而不是自动调整长度以轻松将其拆分为 2 列。有没有办法实现这一点?

In any case, I am creating sections and 2 column lay out as per below suggestion: How to programatically implement Columns in page layout as of in MS Word using python-docx无论如何,我正在按照以下建议创建部分和 2 列布局: 如何使用 python-docx 在 MS Word 中以编程方式实现页面布局中的列

Appreciate any help.感谢任何帮助。

I found the solution - it needed to add me a section break at the end of columns.我找到了解决方案 - 它需要在列的末尾添加一个分节符。 This was just as good as adding a new section as per below:这就像添加一个新部分一样好,如下所示:

section = document.add_section(WD_SECTION.CONTINUOUS) 

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

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