
Table
=====


MS API
------

::

    table = Document.Tables.Add(Range, NumRows, NumCols)
    cell = table.Cell(row, col)


Specimen XML
------------

.. highlight:: xml

The following XML is generated by Word when inserting a 2x2 table::

    <w:tbl>
      <w:tblPr>
        <w:tblStyle w:val="TableGrid"/>
        <w:tblW w:type="auto" w:w="0"/>
        <w:tblLook w:firstColumn="1" w:firstRow="1" w:lastColumn="0"
                   w:lastRow="0" w:noHBand="0" w:noVBand="1" w:val="04A0"/>
      </w:tblPr>
      <w:tblGrid>
        <w:gridCol w:w="4788"/>
        <w:gridCol w:w="4788"/>
      </w:tblGrid>
      <w:tr>
        <w:tc/>
          <w:tcPr>
            <w:tcW w:type="dxa" w:w="4788"/>
          </w:tcPr>
          <w:p/>
        </w:tc>
        <w:tc>
          <w:tcPr>
            <w:tcW w:type="dxa" w:w="4788"/>
          </w:tcPr>
          <w:p/>
        </w:tc>
      </w:tr>
      <w:tr>
        <w:tc>
          <w:tcPr>
            <w:tcW w:type="dxa" w:w="4788"/>
          </w:tcPr>
          <w:p/>
        </w:tc>
        <w:tc>
          <w:tcPr>
            <w:tcW w:type="dxa" w:w="4788"/>
          </w:tcPr>
          <w:p/>
        </w:tc>
      </w:tr>
    </w:tbl>


Minimal XML
-----------

.. highlight:: xml

The following is the minimal XML implied by inserting a 2x2 table::

    <w:tbl>
      <w:tblPr>
        <w:tblW w:type="auto" w:w="0"/>
      </w:tblPr>
      <w:tblGrid>
        <w:gridCol/>
        <w:gridCol/>
      </w:tblGrid>
      <w:tr>
        <w:tc>
          <w:p/>
        </w:tc>
        <w:tc>
          <w:p/>
        </w:tc>
      </w:tr>
      <w:tr>
        <w:tc>
          <w:p/>
        </w:tc>
        <w:tc>
          <w:p/>
        </w:tc>
      </w:tr>
    </w:tbl>


Schema Definitions
------------------

.. highlight:: xml

::

  <xsd:complexType name="CT_Tbl">
    <xsd:sequence>
      <xsd:group   ref="EG_RangeMarkupElements" minOccurs="0" maxOccurs="unbounded"/>
      <xsd:element name="tblPr"   type="CT_TblPr"/>
      <xsd:element name="tblGrid" type="CT_TblGrid"/>
      <xsd:group   ref="EG_ContentRowContent" minOccurs="0" maxOccurs="unbounded"/>
    </xsd:sequence>
  </xsd:complexType>

  <xsd:complexType name="CT_TblPr">  <!-- denormalized -->
    <xsd:sequence>
      <xsd:element name="tblStyle"            type="CT_String"        minOccurs="0"/>
      <xsd:element name="tblpPr"              type="CT_TblPPr"        minOccurs="0" maxOccurs="1"/>
      <xsd:element name="tblOverlap"          type="CT_TblOverlap"    minOccurs="0" maxOccurs="1"/>
      <xsd:element name="bidiVisual"          type="CT_OnOff"         minOccurs="0" maxOccurs="1"/>
      <xsd:element name="tblStyleRowBandSize" type="CT_DecimalNumber" minOccurs="0" maxOccurs="1"/>
      <xsd:element name="tblStyleColBandSize" type="CT_DecimalNumber" minOccurs="0" maxOccurs="1"/>
      <xsd:element name="tblW"                type="CT_TblWidth"      minOccurs="0" maxOccurs="1"/>
      <xsd:element name="jc"                  type="CT_JcTable"       minOccurs="0" maxOccurs="1"/>
      <xsd:element name="tblCellSpacing"      type="CT_TblWidth"      minOccurs="0" maxOccurs="1"/>
      <xsd:element name="tblInd"              type="CT_TblWidth"      minOccurs="0" maxOccurs="1"/>
      <xsd:element name="tblBorders"          type="CT_TblBorders"    minOccurs="0" maxOccurs="1"/>
      <xsd:element name="shd"                 type="CT_Shd"           minOccurs="0" maxOccurs="1"/>
      <xsd:element name="tblLayout"           type="CT_TblLayoutType" minOccurs="0" maxOccurs="1"/>
      <xsd:element name="tblCellMar"          type="CT_TblCellMar"    minOccurs="0" maxOccurs="1"/>
      <xsd:element name="tblLook"             type="CT_TblLook"       minOccurs="0" maxOccurs="1"/>
      <xsd:element name="tblCaption"          type="CT_String"        minOccurs="0" maxOccurs="1"/>
      <xsd:element name="tblDescription"      type="CT_String"        minOccurs="0" maxOccurs="1"/>
      <xsd:element name="tblPrChange"         type="CT_TblPrChange"   minOccurs="0"/>
    </xsd:sequence>

  <xsd:complexType name="CT_TblWidth">
    <xsd:attribute name="w"    type="ST_MeasurementOrPercent"/>
    <xsd:attribute name="type" type="ST_TblWidth"/>
  </xsd:complexType>

  <xsd:complexType name="CT_TblLook">
    <xsd:attribute name="firstRow"    type="s:ST_OnOff"/>
    <xsd:attribute name="lastRow"     type="s:ST_OnOff"/>
    <xsd:attribute name="firstColumn" type="s:ST_OnOff"/>
    <xsd:attribute name="lastColumn"  type="s:ST_OnOff"/>
    <xsd:attribute name="noHBand"     type="s:ST_OnOff"/>
    <xsd:attribute name="noVBand"     type="s:ST_OnOff"/>
    <xsd:attribute name="val"         type="ST_ShortHexNumber"/>
  </xsd:complexType>

  <xsd:complexType name="CT_TblGrid">  <!-- denormalized -->
    <xsd:sequence>
      <xsd:element name="gridCol"       type="CT_TblGridCol"    minOccurs="0" maxOccurs="unbounded"/>
      <xsd:element name="tblGridChange" type="CT_TblGridChange" minOccurs="0"/>
    </xsd:sequence>
  </xsd:complexType>

  <xsd:complexType name="CT_TblGridCol">
    <xsd:attribute name="w" type="s:ST_TwipsMeasure"/>
  </xsd:complexType>

  <xsd:group name="EG_ContentRowContent">
    <xsd:choice>
      <xsd:element name="tr"        type="CT_Row"          minOccurs="0" maxOccurs="unbounded"/>
      <xsd:element name="customXml" type="CT_CustomXmlRow"/>
      <xsd:element name="sdt"       type="CT_SdtRow"/>
      <xsd:group   ref="EG_RunLevelElts"                   minOccurs="0" maxOccurs="unbounded"/>
    </xsd:choice>
  </xsd:group>

  <xsd:complexType name="CT_Row">
    <xsd:sequence>
      <xsd:element name="tblPrEx" type="CT_TblPrEx" minOccurs="0" maxOccurs="1"/>
      <xsd:element name="trPr"    type="CT_TrPr"    minOccurs="0" maxOccurs="1"/>
      <xsd:group   ref="EG_ContentCellContent"      minOccurs="0" maxOccurs="unbounded"/>
    </xsd:sequence>
    <xsd:attribute name="rsidRPr" type="ST_LongHexNumber"/>
    <xsd:attribute name="rsidR"   type="ST_LongHexNumber"/>
    <xsd:attribute name="rsidDel" type="ST_LongHexNumber"/>
    <xsd:attribute name="rsidTr"  type="ST_LongHexNumber"/>
  </xsd:complexType>

  <xsd:group name="EG_ContentCellContent">
    <xsd:choice>
      <xsd:element name="tc"        type="CT_Tc"            minOccurs="0" maxOccurs="unbounded"/>
      <xsd:element name="customXml" type="CT_CustomXmlCell"/>
      <xsd:element name="sdt"       type="CT_SdtCell"/>
      <xsd:group   ref="EG_RunLevelElts"                    minOccurs="0" maxOccurs="unbounded"/>
    </xsd:choice>
  </xsd:group>

  <xsd:complexType name="CT_Tc">
    <xsd:sequence>
      <xsd:element name="tcPr" type="CT_TcPr" minOccurs="0" maxOccurs="1"/>
      <xsd:group   ref="EG_BlockLevelElts"    minOccurs="1" maxOccurs="unbounded"/>
    </xsd:sequence>
    <xsd:attribute name="id" type="s:ST_String" use="optional"/>
  </xsd:complexType>

  <xsd:group name="EG_BlockLevelElts">
    <xsd:choice>
      <xsd:group   ref="EG_BlockLevelChunkElts"       minOccurs="0" maxOccurs="unbounded"/>
      <xsd:element name="altChunk" type="CT_AltChunk" minOccurs="0" maxOccurs="unbounded"/>
    </xsd:choice>
  </xsd:group>

  <xsd:group name="EG_BlockLevelChunkElts">
    <xsd:choice>
      <xsd:group ref="EG_ContentBlockContent" minOccurs="0" maxOccurs="unbounded"/>
    </xsd:choice>
  </xsd:group>

  <xsd:group name="EG_ContentBlockContent">
    <xsd:choice>
      <xsd:element name="customXml" type="CT_CustomXmlBlock"/>
      <xsd:element name="sdt"       type="CT_SdtBlock"/>
      <xsd:element name="p"         type="CT_P"   minOccurs="0" maxOccurs="unbounded"/>
      <xsd:element name="tbl"       type="CT_Tbl" minOccurs="0" maxOccurs="unbounded"/>
      <xsd:group   ref="EG_RunLevelElts"          minOccurs="0" maxOccurs="unbounded"/>
    </xsd:choice>
  </xsd:group>

  <xsd:complexType name="CT_TcPr">  <!-- denormalized -->
    <xsd:sequence>
      <xsd:element name="cnfStyle" type="CT_Cnf" minOccurs="0" maxOccurs="1"/>
      <xsd:element name="tcW" type="CT_TblWidth" minOccurs="0" maxOccurs="1"/>
      <xsd:element name="gridSpan" type="CT_DecimalNumber" minOccurs="0"/>
      <xsd:element name="hMerge" type="CT_HMerge" minOccurs="0"/>
      <xsd:element name="vMerge" type="CT_VMerge" minOccurs="0"/>
      <xsd:element name="tcBorders" type="CT_TcBorders" minOccurs="0" maxOccurs="1"/>
      <xsd:element name="shd" type="CT_Shd" minOccurs="0"/>
      <xsd:element name="noWrap" type="CT_OnOff" minOccurs="0"/>
      <xsd:element name="tcMar" type="CT_TcMar" minOccurs="0" maxOccurs="1"/>
      <xsd:element name="textDirection" type="CT_TextDirection" minOccurs="0" maxOccurs="1"/>
      <xsd:element name="tcFitText" type="CT_OnOff" minOccurs="0" maxOccurs="1"/>
      <xsd:element name="vAlign" type="CT_VerticalJc" minOccurs="0"/>
      <xsd:element name="hideMark" type="CT_OnOff" minOccurs="0"/>
      <xsd:element name="headers" type="CT_Headers" minOccurs="0"/>
      <xsd:group ref="EG_CellMarkupElements" minOccurs="0" maxOccurs="1"/>
      <xsd:element name="tcPrChange" type="CT_TcPrChange" minOccurs="0"/>
    </xsd:sequence>
  </xsd:complexType>

::

    w_CT_Tc =
      attribute w:id { s_ST_String }?,
      element tcPr { w_CT_TcPr }?,
      w_EG_BlockLevelElts+

    w_EG_BlockLevelElts =  # denormalized
      element customXml { w_CT_CustomXmlBlock }
      | element p { w_CT_P }
      | element sdt { w_CT_SdtBlock }
      | element tbl { w_CT_Tbl }
      | element altChunk { w_CT_AltChunk }

      | element proofErr { w_CT_ProofErr }
      | element permStart { w_CT_PermStart }
      | element permEnd { w_CT_Perm }
      | element ins { w_CT_RunTrackChange }
      | element del { w_CT_RunTrackChange }
      | element moveFrom { w_CT_RunTrackChange }
      | element moveTo { w_CT_RunTrackChange }

      | element bookmarkStart { w_CT_Bookmark }
      | element bookmarkEnd { w_CT_MarkupRange }
      | element moveFromRangeStart { w_CT_MoveBookmark }
      | element moveFromRangeEnd { w_CT_MarkupRange }
      | element moveToRangeStart { w_CT_MoveBookmark }
      | element moveToRangeEnd { w_CT_MarkupRange }
      | element commentRangeStart { w_CT_MarkupRange }
      | element commentRangeEnd { w_CT_MarkupRange }
      | element customXmlInsRangeStart { w_CT_TrackChange }
      | element customXmlInsRangeEnd { w_CT_Markup }
      | element customXmlDelRangeStart { w_CT_TrackChange }
      | element customXmlDelRangeEnd { w_CT_Markup }
      | element customXmlMoveFromRangeStart { w_CT_TrackChange }
      | element customXmlMoveFromRangeEnd { w_CT_Markup }
      | element customXmlMoveToRangeStart { w_CT_TrackChange }
      | element customXmlMoveToRangeEnd { w_CT_Markup }

      | element oMathPara { m_CT_OMathPara }
      | element oMath { m_CT_OMath }


Resources
---------

* `Tables.Add Method on MSDN`_

.. _Tables.Add Method on MSDN:
   http://msdn.microsoft.com/en-us/library/office/microsoft.office.interop.wo
   rd.tables.add(v=office.14).aspx

* `Table Members on MSDN`_

.. _`Table Members on MSDN`:
   http://msdn.microsoft.com/en-us/library/office/microsoft.office.interop.wo
   od.table_members(v=office.14).aspx
