python-文档之间插入熊猫的数据框
我有一个pandas
数据框架,我想在Word Document
之间插入它。假设 -
- 第1节
这是测试Word文档
在此处插入表
- 第2节
应在第2节之前插入表。
表。应在此处插入PANDAS数据框架。
我检查了python-docx
,我们可以很容易地插入表,但是该表将在文档的末尾插入。
我们可以使用Python-docx在文档之间插入表。如果没有,有人可以建议我可以用来实现此功能的其他库。
I have a pandas
data frame which I want to insert in between of a word document
. Let's say -
- Section 1
This is test word document
insert table here
- Section 2
Table should be inserted before section 2.
Pandas data frame should be inserted in place of insert table here
.
I checked python-docx
, we can insert table very easily but that table will be inserted at the end of a document.
Can we insert table in between of the document using python-docx. If not, can someone suggest other library which I can use to achieve this functionality.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用aspose.words轻松实现此目标。在您的情况下,您可以将书签插入占位符,您需要在其中插入表格,然后使用
docudmenbuilder
在书签上插入表。例如,请参见以下简单代码:aspose.words for python文档,以了解有关使用书签和与桌子一起工作。
更新:如果您需要使用文本作为占位持有人,则可以使用以下代码:
在.net和Java版本的Aspose.Words。您可以使用
ireplacingCallback
来实现这一目标,但在Python版本中此功能尚不可用。irePlacingCallback
允许执行自定义操作。除表外,您可以插入另一个文档的内容,只需使用documentBuilder.insert_document方法即可。代码看起来像这样:
You can easily achieve this using Aspose.Words. In your case, you can insert bookmark as a placeholder where you need to insert a table and then use
DocumentBuilder
to insert table at the bookmark. For example see the following simple code:Ass Aspose.Words for Python documentation to learn more about working with bookmarks and working with tables.
UPDATE: If you need to use a text as a placeholder, you can use code like the following:
In .NET and Java version of Aspose.Words you can use
IReplacingCallback
to achieve this, but in Python version this feature is not available yet.IReplacingCallback
allows to perform a custom actions whenRange.Replace
action is performed.Except table, you can insert content of another document, simply use DocumentBuilder.insert_document method. Code will look like this: