python docx WD_CELL_VERTICAL_ALIGNMENT 未检测到成员

python docx WD_CELL_VERTICAL_ALIGNMENT member not detected

所以我试图将 table 单元格与这样的代码对齐:

from docx import *
import re
from copy import deepcopy
from docx.enum.table import WD_TABLE_ALIGNMENT, WD_CELL_VERTICAL_ALIGNMENT as WD_ALIGN_VERTICAL
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT as WD_ALIGN_PARAGRAPH
from docx.shared import Pt
from docx.enum.style import WD_BUILTIN_STYLE
import sys

def writeNormalStyle(cell,fill):
cell.vertical_alignment = WD_ALIGN_VERTICAL.CENTER
cell_bobot = cell.paragraphs[0]
cell_bobot.alignment = WD_ALIGN_PARAGRAPH.CENTER
cell_bobot.text = fill

def writeBoldStyle(cell,fill):
cell.vertical_alignment = WD_ALIGN_VERTICAL.CENTER
cell_paragraph = cell.paragraphs[0]
cell_paragraph.alignment = WD_ALIGN_PARAGRAPH.CENTER
cell_paragraph.add_run(fill).bold = True

但随后出现错误 Class 'WD_CELL_VERTICAL_ALIGNMENT' has no 'CENTER' memberpylint(no-member) 我不知道为什么会发生这种情况,因为如文档所述,CENTER 应该存在于此 class 中,并且该错误也适用于 class WD_ALIGN_PARAGRAPH.CENTER

谢谢,如有任何建议,我们将不胜感激

我假设代码按预期工作。此错误似乎来自 pylint,它可能无法检测到创建枚举的 metaclass 提供给它的 class 成员。您可能需要配置 linter 以忽略此错误。