how to prevent text wrap in powerpoint table cell using python-pptx

1.7k views Asked by At

In some rows of a table, a long text string in column 1 needs to continue over columns 2, 3, and 4, instead of wrapping. How would I either merge the cells or prevent the text from wrapping so that it continues over the subsequent columns? I have tried setting word_wrap on the text frame as follows but it changes nothing:

table = shape.table
cell = table.rows[0].cells[1]
cell.text_frame.word_wrap = False

I have also tried setting text_frame.auto_size to MSO_AUTO_SIZE.SHAPE_TO_FIT_TEXT but that also changes nothing.

1

There are 1 answers

0
scanny On

I think what you're looking for here is "cell merge".

In Excel, text that extends past a cell boundary automatically extends into the adjacent cell (if it's empty), but PowerPoint doesn't work that way.

Unfortunately, python-pptx doesn't have table cell merge capability yet, so the only way you'd be able to fit longer text is to make the column wider.