Home > front end >  how do I write this style command as a key to fix this error?
how do I write this style command as a key to fix this error?

Time:06-30

Can anyone tell me how to fix this?

table = document.add_table(rows=1, cols=3)
table.style = 'LightShading-Accent6'
for i in range(3):
    table.rows[0].cells[i].text = table_header[i]

I am getting the error

C:\Users\AppData\Local\Programs\Python\Python310\lib\site-packages\docx\styles\styles.py:139: 
UserWarning: style lookup by style_id is deprecated. Use style name as key instead.
  return self._get_style_id_from_style(self[style_name], style_type)

CodePudding user response:

The message you have is a warning, not an error. You should still fix it of course.

The name corresponding to the style ID LightShading-Accent6 is Light Shading Accent 6, so use that instead. Names are generally just the ID written out in title case with proper human-readable spacing:

table.style = 'Light Shading Accent 6'
  • Related