wordpress hit counter
Re: GridSpan - increasing cell width - Open XML SDK 2.0 - Development Tools - OpenXML Developer

Re: GridSpan - increasing cell width

Development Tools

Discussions about working with Open XML using a wide range of development tools

GridSpan - increasing cell width

  • rated by 0 users
  • This post has 3 Replies |
  • 3 Followers
  • Hi,

    I am working on Word 2007 document and has a requirement to increase the cell width. Manually if I increase the width of the cell it works but using Open XML SDK if I try to increase the width of the cell it's affecting the whole Column in the table. I tried to altogether remove the cells from the Row and re-add cells with increased width and grid span but its not working.

    Please suggest.

     

     

     

     

  • There are three kinds of things that need to change in the body of the document to achieve what you're asking..

    1) Update the GridColumns in the TableGrid (a table in a WordprocessingML always has this TableGrid to locate the borders of all columns)
    2) Change the TableCell width's appropriately (as you've done)
    3) Add GridSpans to the TableCellProperties that span multiple GridColumns (created in #1)

    To demonstrate this I'll present a simple scenario:
    We have a normal 2 column by 3 row table, and we want the middle row's left cell to be wide (and subsequently the right cell to be narrower).  Lets say the two columns are of equal width of 2000px and we want the middle row's left cell width to increase by 500px.  Following what I stated above, here's what we would need to do:
    1) In the Body of the document we will have a Table containing a TableGrid OpenXmlElement.  Within this TableGrid element we would find two GridColumn elements, each with their Width property set to "2000".  We need to change the second GridColumn's Width property to "500" (because this is the offset we want for our middle row's column to finish).  Then we need to add a last GridColumn with a Width property of "1500".
    2) In the Table's middle TableRow there will be two TableCells.  The width for the TableCell is found in its TableCellProperties element which will itself contain a TableCellWidth.  The TableCellWidth will have a property Width.  Change the first of the row's TableCell width to "2500" and change the second TableCell width to "1500".
    3) Within each TableCell's TableCellProperties element there is also a GridSpan.  For the first TableRow we need to give the second TableCell a GridSpan with a Val of 2 (so that it spans over the two right hand GridColumns we made in step #1).  Then, for the second TableRow, we need to give the first TableCell a GridSpan with a Val of 2.  And finally, for the third TableRow we need to give the second TableCell a GridSpan with a Val of 2.

    Now you should get the outcome you were hoping for - it was only a problem because the table in a WordprocessingML will follow the TableGrid layout.
  • It's helpful!!

  • Hi, your solution is definitely helpful. I have the same problem but I have to set cell widths and row heights for a table that is 17 columns wide by 125 rows high. Is the solution described above stil the best (or erven the only) way to go?

    I had an idea of splitting the one multirow table into many single row tables. As each of them (single row tables) contains just one row the cell widths for each cell can be set indepedently. Once set I will then need to somehow merge the single row tables into one multirow table. The problem is that when I do it in MSWord (remove the carriage returns separating each single row tables) themultirow table gets created and the cell widths remain as they were. When I try to do the same in OpenXML (using body.RemoveAllChildren<Paragraph>();) the cell widths of the last single row table affect all the preceding rows and I end up having all cells following TableGrid layout.

    Any suggestions please?

Page 1 of 1 (4 items)