I want to define a function to filling header colour, for now, I am just hard code every object.
Here is the code I used, I tried to define a function to add cell colour.
The error msg shown below:
from docx import Document
from openpyxl import load_workbook
from docx.oxml import OxmlElement
from docx.oxml.ns import qn
from zmq import NULL
document = Document()
k=1
for k in range (1,5):
table = document.add_table(rows=2, cols=3)
table.cell(0,0).text = ('Type')
table.cell(0,1).text = ('Value')
table.cell(0,2).text = ('Connections')
def set_table_header_bg_color(table.rows[row_ix].cell):
"""
set background shading for Header Rows
"""
tblCell = cell._tc
tblCellProperties = tc.get_or_add_tcPr()
clShading = OxmlElement('w:shd')
clShading.set(qn('w:fill'), "00519E") #Hex of Dark Blue Shade {R:0x00, G:0x51, B:0x9E}
tblCellProperties.append(clShading)
return cell
for each_row in table.rows :
for each_cell in each_row.cells:
set_table_header_bg_color(each_cell)
Could you guys help me to solve this error? I copy this function from https://stackoverflow.com/a/62079054/18540814 but the function seems cannot use in my case......