Worksheets

Worksheets are saved as a table. In Microsoft Excel, the table contains the smallest rectangular range of cells that contain data and formatting, including cell A1. HTML 3.2 is used for the basic table, while formatting, alignment, and sizing are specified using a combination of CSS and HTML. The table is contained in a Table element placed immediately after the Body element. The border, cellspacing, cellpadding, width, and style attributes are specified in the Table element so that the table more closely resembles a worksheet when viewed in a Web browser.


<table x:str border=0 cellpadding=0 cellspacing=0 width=64
  style='border-collapse:collapse;table-layout:fixed;width:48pt'>

A Col element is placed immediately after the Table element for each column of the table. The width attribute and width style attribute specify the width of the column in pixels, and the style attribute specifies the column style. If consecutive columns contain the same attributes, the span attribute can be used to apply the attributes to the columns: for example, <col class=XL4 width=216 span=2> instead of <col class=XL4 width=216><col class=XL4 width=216> is specified. Hidden columns are specified with the display:none style.

Each row is contained in a TR element. The height attribute and height style attribute specify the height of the row in pixels. Hidden rows are specified with the display:none style.

Each cell is contained in a TD element. In every cell of the first row and in every cell that has wordwrap enabled, the width attribute specifies the width of the column in pixels. In the first cell of each row, the height attribute specifies the height of the row in pixels. Empty cells contain a single non-breaking space (&nbsp;) in the TD element.

Both an element attribute and a style attribute are used to specify row height and column width. If the element attribute value differs from the style attribute value, Excel uses the greater value. The default height and width are specified by the mso-default-height and mso-default-width style attributes of the Table element. The mso-space-above, mso-space-below, mso-unsynced, and mso-zero-height style attributes are also used.

If the default height is set by the user, the mso-height-source: userset style is used in the TR element. If the height is automatically set, the mso-height-source: auto style is used. For files that were not created by Excel, rows that have a height specified but do not include a mso-height-source style attribute have a default style attribute value of userset.

The user-defined height must also be specified using the mso-height-alt style attribute of the TR element. The mso-height-alt style attribute specifies the height in the units used by Excel.

Alignment

The align attribute of the TD element and the text-align style attribute specify the horizontal alignment of a cell. The valign attribute of the TD element and the vertical-align style attribute specify the vertical alignment.

When a cell containing text has general horizontal alignment or is aligned to the left, the align attribute is not specified. The vertical alignment of a row is specified for each TR element. If no formatting has been applied, the cell is aligned towards the bottom by default.

Merged cells

The colspan and rowspan attributes are used to specify merged cells. For horizontally merged cells, the colspan attribute is used in the TD element of the leftmost cell. For vertically merged cells, the rowspan attribute is used in the TD element of the topmost cell. For cells merged in both directions, the attributes are used in the TD element of the top left cell. The mso-ignore: colspan style is used when the contents of a cell can be displayed over adjacent empty cells that do not contain visible formatting such as backgrounds, patterns, and borders. The style specifies that the cells should not be merged when the file is opened in Excel. If the empty cells have formatting applied, the mso-spanned-cells style attribute is used containing a list of classes used by the cells in the table. A class name is specified for each cell, and each class name is separated by a space. If the cell has no formatting, none is specified.

If the adjacent cells are not empty or contain visible formatting, a Span element and the display: none style are specified. The Span element contains the fragment of content clipped by the content of the adjacent cell.

Hidden data

Columns and rows in the table are hidden by specifying a height or width of 0 (zero) and, if the Web browser supports styles, by specifying the display: none style in the Col or TR element. The mso-height, mso-height-alt, mso-width, mso-width-alt, and mso-height-source: userset style attributes and styles specify the height and width of the column or row when visible in Excel. Width is assumed to be user-defined for hidden columns.

A worksheet is hidden by not specifying a link to the file in the workbook frameset and by specifying the display: none style in the Body element of the worksheet file. The workbook tab strip file contains tabs for visible worksheets only.

Empty columns and rows

If a table contains two or more adjacent empty columns or rows that are not formatted, the colspans and xlrowspans attributes and the mso-ignore style attribute are used to display them. These attributes are specified when the document is saved and not when it is published. The xlrowspan attribute can be used in the first TR element containing the top row. The colspan attribute is used in the Col element for the leftmost column. The attributes contain a value specifying the total number of adjacent empty columns or rows.

Page breaks in tables

Page breaks are saved using the subelements of the XML PageBreaks element. Horizontal page breaks are specified using the page-break-before: always style of the TR element following the break.

Worksheet background

The background attribute of the Body element specifies the background image of a worksheet.