如何从Word(.docx)复制段落(具有数字格式)和图像,并使用Python粘贴到Excel(.xlsx)中

问题描述 投票:1回答:1

我有Words(.docx)格式的合同条款,需要经常复制并粘贴到Excel(.xlsx)中才能发送给第三方。子句经常更新,因此始终需要复制并粘贴这些子句。我只需要复制并粘贴内容页面的所有段落和图像。这是Clause document的示例。我已经尝试使用Python编写代码以实现此结果。这是到目前为止我完成的代码:

!pip install python-docx import docx import xlsxwriter document = docx.Document("Clauses Sample.docx") wb = xlsxwriter.Workbook('C:/xxxx/xxxxxx/xxxx/clauses sample.xlsx') docText = [] index_row = 0 Sheet1 = wb.add_worksheet("Sheetttt") for paragraph in document.paragraphs: if paragraph.text: docText.append(paragraph.text) xx = '\n'.join(docText) Sheet1.write(index_row,0, xx) index_row = index_row+1 wb.close() #print(xx)

但是,我的Excel文件输出看起来像这样:

enter image description here

但是我希望我的Excel输出看起来像这样,例如:enter image description hereenter image description here

有什么办法可以得到想要的输出?

我有Words(.docx)格式的合同条款,需要经常复制并粘贴到Excel(.xlsx)中才能发送给第三方。子句经常更新,因此始终需要...

python excel ms-word copy-paste
1个回答
0
投票
这里有两个问题(和解决方案),我认为它们可以使您更加接近。
© www.soinside.com 2019 - 2024. All rights reserved.