locked
OpenXML2.0 Table Cell Margin RRS feed

  • Question

  • Hello all,

    How can I set the table cell margin programmatically? I have set the vertical align of table cell and it works well. But with some reason, text in the table cell is located in the top of cell like below image. When I increase the height of this table cell then I can see the text is located in Vertical Center well. I did not set any properties of table cell like height, margin, etc.. It's default state. Every texts located in table cell in my document does like the ceiling too much. :-)

    Thanks for your help in advance

    Following is a part of my code:

    private TableCell CreateTableCell_S(string _string, int _stringStyle, .....)
            {
                // Table cell which will contain all tableCellProperties
                TableCell tc = new TableCell();

                // Table Cell Properties Definition
                TableCellProperties _tcp = new TableCellProperties();

                // Add table cell width
                TableCellWidth _tcw = new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = _width.ToString() };
                _tcp.Append(_tcw);

                // Add table cell span - horizontal cell spanning
                GridSpan _sp1 = new GridSpan() { Val = _gridSpanColumn };
                _tcp.Append(_sp1);

                tc.Append(_tcp);

                if (_string != "")
                    tc.Append(this.SetParagraph(_string, _stringStyle, _horizonAlign));

                return tc;
            }


    Alvin
    Tuesday, December 20, 2011 6:50 AM

All replies

  • Hi Alvin,

     

    Thanks for posting in the MSDN Forum.

     

    As far as I know that that we are able to set vertical center alignment via TableCellVerticalAlignment under TableCellProperties.

     

    I hope it can help you.

     

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    • Marked as answer by 许阳(无锡) Tuesday, December 27, 2011 5:17 AM
    • Unmarked as answer by Alvin KY Wednesday, December 28, 2011 11:44 PM
    Thursday, December 22, 2011 6:03 AM
  • Yes I know. I am already using that property. below is the part of my code to set the vertical alignment:

    // Add table cell text alignment
                TableCellVerticalAlignment _tcv = new TableCellVerticalAlignment();
                if (_verticalAlign == (int)ENUMTableCellVerticalAlign.TOP) _tcv = new TableCellVerticalAlignment() { Val = TableVerticalAlignmentValues.Top };
                if (_verticalAlign == (int)ENUMTableCellVerticalAlign.MIDDLE) _tcv = new TableCellVerticalAlignment() { Val = TableVerticalAlignmentValues.Center };
                if (_verticalAlign == (int)ENUMTableCellVerticalAlign.BOTTOM) _tcv = new TableCellVerticalAlignment() { Val = TableVerticalAlignmentValues.Bottom };
                _tcp.Append(_tcv);

     

    All table cells I have has a default vertical alignment with CENTER by using above code.
    As I've put down, it's not well aligned vertically. When I increase the height of cell manually then I can see the text in vertically center. But in default state, it's not.

    Thanks 


    Alvin
    Wednesday, December 28, 2011 11:43 PM
  • Hi Alvin

    Do you know what the paragraph formatting is of the text in the cell? More specifically, the Space After setting? That will affect how the cells display paragraphs.

    Click in the paragraph, go to the Home/Paragraphs group in the Ribbon and click the dialog box launcher. About half way down the first tab you should see the settings for space before and after. My guess would be that Space After is set to something > 0. Change it to 0 and see if that's more what you have in mind?


    Cindy Meister, VSTO/Word MVP
    Sunday, January 1, 2012 8:57 AM