python-3.x - 如何使用python在docx中获取单元格文本旋转?
问题描述
我正在编写 Python 脚本以从 MS Word 表中获取数据并在另一个应用程序中绘制此类表。所以我无法解决如何在现有 Word 文档中获取有关单元格文本旋转的信息的问题。
我使用现有的解决方案来设置单元格文本旋转。
def get_vertical_cell_direction(cell: _Cell):
tc = cell._tc
tcPr = tc.get_or_add_tcPr()
return tcPr
此代码返回:“CT_TcPr at 0x2e102875958>” 阅读 docx 文档我很困惑接下来要做什么来获取 textDirection 属性。
解决方案
与我问的其他问题相同,它需要检查单元格的 xml 代码:
def get_text_direction(cell):
# direction: tbRl -- top to bottom, btLr -- bottom to top
pattern = re.compile('w:textDirection w:val=\"(\S*)\"')
match = pattern.search(cell._tc.xml)
if match:
txt = match.group(1)
if txt == 'btLr':
return 90
elif txt == 'tbRl':
return -90
return 0
推荐阅读
- go - 使用 CView 创建 TUI:网格和使部件不可选择
- docker - 使用代理防火墙构建 docker 映像错误
- reactjs - 如何让 react-datepicker 在星期一开始一周中的几天?
- spring-boot - 无法在兔子侦听器springboot中检索x-death标头
- reactjs - 我的 Axios 的动态 API 路径似乎没有正确形成
- powershell - AutoIt 复选框按钮单击
- python - 使用python检查文件中的名称是否匹配
- c++ - 编写将唯一指针推入向量的函数时出错
- node.js - Bitstamp 认证 API hmac
- kubernetes - 即使成功启用 Bolt,也无法建立与 Neo4j 使用螺栓方案的连接