Search code examples
pythonalignmentpython-docx

python docx WD_CELL_VERTICAL_ALIGNMENT member not detected


So i was trying to align a table cell with code like this :

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

but then error appeared Class 'WD_CELL_VERTICAL_ALIGNMENT' has no 'CENTER' memberpylint(no-member) i have no idea why this happen cause CENTER should exist in this class as the documentation said, and the error also apply to class WD_ALIGN_PARAGRAPH.CENTER

Thankyou, any advice is appreciated


Solution

  • I assume the code works as intended. This error appears to be coming from pylint, which perhaps is unable to detect the class members given to it by the metaclass that creates the enumeration. You may want to configure your linter to ignore this error.