使用Python复制从Word File到PowerPoint Textbox的同一格式的文本
我正在尝试使用Python将文本从Word文档复制到PowerPoint文本框中。我希望与一个完全相同的格式中的Word文档中的所有文本插入一个PowerPoint文本框。这里的问题是其中一些段落是粗体的,有些则不是。我不确定这是否可能。请参阅下面的Word Doc的样子: -
这就是应该看起来的外观就像在ppt中(在一个文本框中)
我正在使用python docx和pptx库但是我不是他们的专家。请帮忙!
编辑:
到目前为止,我尝试过的一些事情: -
我找到了一个代码,可以复制带有样式的文本,但它是用于Word到Word的。
def get_para_data(output_doc_name, paragraph):
"""
Write the run to the new file and then set its font, bold, alignment, color etc. data.
"""
output_para = output_doc_name.add_paragraph()
for run in paragraph.runs:
output_run = output_para.add_run(run.text)
# Run's bold data
output_run.bold = run.bold
# Run's italic data
output_run.italic = run.italic
# Run's underline data
output_run.underline = run.underline
# Run's color data
output_run.font.color.rgb = run.font.color.rgb
# Run's font data
output_run.style.name = run.style.name
# Paragraph's alignment data
output_para.paragraph_format.alignment = paragraph.paragraph_format.alignment
input_doc = Document('InputDoc.docx')
output_doc = Document()
# Call the function
get_para_data(output_doc, input_doc.paragraphs[3])
# Save the new file
output_doc.save('OutputDoc.docx')
请让我知道如何从Word到PowerPoint。
I'm trying to copy texts from the word document into a PowerPoint text box using Python. I want all the texts in the word document in the exact same formatting into one PowerPoint text box. The problem here is some of the paragraphs are in bold and some are not. I'm not sure if this is even possible. Please see below how the word doc looks like:-
And this is how it should look like in the ppt (In one text box)
I'm using python docx and pptx library but I'm not expert in them. Please help!
Edit:
some of the things I've tried so far:-
I found one code to copy texts with styles but it is for word to word.
def get_para_data(output_doc_name, paragraph):
"""
Write the run to the new file and then set its font, bold, alignment, color etc. data.
"""
output_para = output_doc_name.add_paragraph()
for run in paragraph.runs:
output_run = output_para.add_run(run.text)
# Run's bold data
output_run.bold = run.bold
# Run's italic data
output_run.italic = run.italic
# Run's underline data
output_run.underline = run.underline
# Run's color data
output_run.font.color.rgb = run.font.color.rgb
# Run's font data
output_run.style.name = run.style.name
# Paragraph's alignment data
output_para.paragraph_format.alignment = paragraph.paragraph_format.alignment
input_doc = Document('InputDoc.docx')
output_doc = Document()
# Call the function
get_para_data(output_doc, input_doc.paragraphs[3])
# Save the new file
output_doc.save('OutputDoc.docx')
Please let me know how to do this from word to PowerPoint.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论