我正在尝试构建包含孟加拉语言的doc文件,但已保存的docx文件在python docx库中不显示任何字符

问题描述 投票:0回答:1
document = Document()

document.add_heading(header, 0)

document.add_paragraph('বাংলা ভাষা টেক্সট')



document.add_page_break()

document.save('DownloadableFiles\\DOCX_FILES\\'+file_name+'.docx')

但文件显示

“一些盒子的截图”

python python-docx
1个回答
0
投票

如果我运行此代码,精简了一下并使用python-docx软件包,对我来说很好用:

from docx import Document

document = Document()
document.add_paragraph('বাংলা ভাষা টেক্সট')
document.add_page_break()
document.save('test.docx')

当我在LibreOffice中打开生成的文档时,看到:

characters that look about right to my ignorant eye

因此,我怀疑问题不在于您的Python代码,而在于您的Word安装或字体(更可能是字体)。也许您需要显式安装或切换为支持这些字符的字体。

© www.soinside.com 2019 - 2024. All rights reserved.