New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modify the alignment of cells in a table #153
Comments
I don't believe there is such a setting in Word, Bryan. You can achieve this effect by setting the alignment (justification) of each paragraph in the cell, and you can set each of those separately, perhaps centering the first one and making the rest left justified. There may be something you can do with table styles though. If you can create a Word document by hand that exhibits the behavior you're after we can take a deeper look. |
Ah thanks. I made the cardinal mistake of mixing a requirement with a possible solution. The requirement I have is that I can create aligned cells in a table. Following your hint above I can do that simply by aligning the paragraphs in the cells as I create them (which is what I wanted, but I foolishly suggested a way of doing it based on the way I had to handle cell width ... I hadn't appreciated the extra complexity of the paragraphs within the cell ... despite it being pretty obvious if I'd thought about it). In case anyone else comes here, this is the way of doing it: # add a row with one cell left aligned, then one right aligned:
row=table.add_row().cells
p=row[0].add_paragraph('left justified text')
p.alignment=WD_ALIGN_PARAGRAPH.LEFT
p=row[1].add_paragraph('right justified text')
p.alignment=WD_ALIGN_PARAGRAPH.RIGHT |
Glad it worked out Bryan :) |
This works, however the tabe cells are now much higher, than were before. Any idea how to change that? |
For fix an extra \n try this:
|
get an extra \n,how to fix it? |
I solved this problem just now,should not add a new paragraph,just get a origin cell paragraph and set it,like this |
Thanks :-) |
If it helps, there is a pretty convenient way to change the style of all cells (or selected ones) of a table like this:
Or if the cell is more complex (i.e. more paragraphs), then this will do it:
|
Rafael, amazing solution !! Thank you bro |
Hi ...
Would it be possible to add an attribute to table cells so it is possible to set the horizontal alignment (left/centred/right) per cell? I imagine the API would be the same as setting the cell width ... so it would be something like the following to have a left justified first column and right justified columns thereafter (as one might do with a spreadsheet of numbers):
The text was updated successfully, but these errors were encountered: