首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Docx-Python更改文本不透明度

Docx-Python更改文本不透明度
EN

Stack Overflow用户
提问于 2018-07-16 13:04:37
回答 1查看 167关注 0票数 0

我正在替换一个docx文件中的文本,该文件最初的文本不透明度为25%,但是当我执行脚本时,更改后的段落的不透明度返回到0%。有没有办法在类似字体大小、斜体等的不透明度中编程?我在docx-python文档中没有找到任何东西。

编辑:这是代码的docx部分。

代码语言:javascript
复制
styles = d.styles
style = styles.add_style('Main Text', WD_STYLE_TYPE.PARAGRAPH)
mainStyle = d.styles['Main Text']
fontMain = mainStyle.font
fontMain.name = 'Montserrat Light'
fontMain.size = Pt(12)

styles = d.styles
style = styles.add_style('Main Run Text', WD_STYLE_TYPE.CHARACTER)
mainRunStyle = d.styles['Main Run Text']
fontRunMain = mainRunStyle.font
fontRunMain.name = 'Montserrat Light'
fontRunMain.size = Pt(12)

currentDate = datetime.date.today()
currentDateFormatted = currentDate.strftime("%B %d, %Y")
d.paragraphs[10].text = currentDateFormatted

d.paragraphs[12].text = 'Jimmy Newtron' #replace with argument
pName = d.paragraphs[12]
pName.style = d.styles['Main Text']

d.paragraphs[13].text = 'Lead Recruiter' #replace with argument
pTitle = d.paragraphs[13]
pTitle.style = d.styles['Main Text']

d.paragraphs[14].text = 'Mega Corp' #replace with argument
pCompany = d.paragraphs[14]
pCompany.style = d.styles['Main Text']

d.paragraphs[15].text = 'New York City, New York, United States' #replace with argument
pLocation = d.paragraphs[15]
pLocation.style = d.styles['Main Text']

d.paragraphs[17].runs[2].text = 'Jimmy Newtron' #replace with argument
rDear = d.paragraphs[17].runs[2]
rDear.style = d.styles['Main Run Text']

d.paragraphs[18].runs[2].text = 'Mega Corp' #replace with argument
rCompany = d.paragraphs[18].runs[2]
rCompany.style = d.styles['Main Run Text']

d.paragraphs[21].runs[3].text = 'Mega Corp' #replace with argument
rCompanyTwo = d.paragraphs[21].runs[3]
rCompanyTwo = d.styles['Main Run Text']

d.save('c:\\users\\sonorityscape\\desktop\\test.docx')
EN

回答 1

Stack Overflow用户

发布于 2018-07-17 04:03:23

我找到的一个解决方案是将文本保存为run而不是段落。出于某种原因,它会保留您在原始文档中保存的透明度/不透明度。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51354881

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档