Both HTML and CSS are used to format cells. The default cell formatting is specified in a style definition for the TD element. The following example shows a style definition for the default cell formatting.
TD {mso-style-name: normal; mso-numberformat:general;
text-align: left; vertical-align: bottom;
font-family:arial; font-size:10pt; color:black}
When only a portion of a cell is formatted, the Span element is used to contain the formatted text fragment.
Cell protection and visibility are also specified using styles. The mso-protection style attribute is used to specify whether a cell is hidden and locked.
The class name for styles consists of the word style followed by a number. Styles used in Microsoft Excel contain the mso-style-name style attribute, specifying the name of the style, and the mso-style-id style attribute, specifying the style index. The mso-style-id style attribute is not used in the user-defined and Normal style definitions.
The style0 style class specifies the formatting for Normal style. The following example shows a style definition for the Normal style.
.style0 {mso-style-name:normal; mso-numberformat:general;
text-align: left; vertical-align: bottom;
font-family:arial; font-size:10pt; color:black}
In Microsoft Excel, the padding style is used to specify padding between the cell text and the side of the cell. For example, the following style definition is used to specify the style of a TD element.
TD { padding: 1px; mso-ignore: padding; }
The padding is not specified if the Normal style is used and the text is indented, or if the worksheet is published using the Spreadsheet component.
Cells can have formatting that is applied as a result of a condition or number format. For example, the color of a number can depend on a condition. In this case, a style attribute is applied to the cell in addition to the style class. The style specifies the current cell format, while the style class specifies the default formatting. The mso-ignore: style style is used to specify that the current style results from a condition.
If a number format is applied, Microsoft Excel uses the number format and the cell value to determine the formatting of a style class. Excel creates a class name for each unique combination of formatting. The cells in the table use the class attribute to specify the style class, and the x:num attribute is specified when a number format is applied. The mso-number-format style is used to specify the number format string. If a user creates a custom number format, the string is specified as the value of the mso-number-format style attribute. Only number formats that are used are saved in the workbook.
If an international file is saved with a locale-specific built-in number format but opened using a version of Excel that does not have the built-in format, the format is treated as a custom number format.
The mso-displayed-decimal-separator and mso-displayed-thousand-separator style attributes of the Table element specify the decimal and thousand separators applied in table cells that do not use the x:num attribute.
The following tables show the styles or HTML elements and attributes used by Microsoft Excel to specify cell alignment. In general, alignment is specified only when it is different from the default alignment, and styles applied to the table apply to each row, column, and cell. Styles applied to a row only apply to cells of the row, and styles applied to a column only apply to cells of the column. Styles applied to rows, columns, or cells take precedence over styles applied to the table elements they are contained in.
For the Spreadsheet component, the text-align and vertical-align styles are ignored, and the align and valign attributes of the TD element are used instead. Fill, justify, and left are not supported with indent alignment styles.
Horizontal alignment | HTML | Style |
General, and the cell contains a numerical value | <TD ALIGN=right> | None. Left alignment is the default alignment in Web browsers. When a cell contains general alignment and the Normal style is not general-aligned, the text-align: auto style is used to specify general alignment. |
General, and the cell contains a non-numerical value | None. Left alignment is the default alignment in Web browsers. | None. Left alignment is the default alignment in Web browsers. When a cell contains general alignment and the Normal style is not general-aligned, the text-align: auto style is used to specify general alignment. |
Left | None. Left alignment is the default alignment in Web browsers. | text-align: left |
Left with indent | None. Left alignment is the default alignment in Web browsers. | text-align: left; margin-left: ems |
Center | <TD ALIGN=center> | text-align: center |
Right | <TD ALIGN=right> | text-align: right |
Fill | None | text-align: fill |
Justify | None | text-align: justify |
Center across selection | <TD COLSPAN=# of cells in selection ALIGN=center> | colspan; mso-ignore: colspan; text-align: center |
If a cell contains a number, the align attribute contains right, and no alignment style is specified, then the cell gets general alignment. In the following example, the first cell gets general alignment, but the second cell is aligned to the right because both the text-align: right and alignment style are specified.
<style><!--
TD {font-size:10pt; font-family: arial}
.XL1 {text-align: right}
--></style>
.
.
.
<tr>
<td align=right>19</td>
<td align=right class=XL1>97</td>
</tr>
Vertical alignment | HTML | Style |
Top | <TD VALIGN=top> | vertical-align: top |
Center | <TD VALIGN=middle> | vertical-align: middle |
Bottom (default) | <TD VALIGN=bottom> (specified in each TR element) | vertical-align: bottom |
Justify | None | vertical-align: justify |
Alignment options | HTML | Style |
Wordwrap | <TD WIDTH=# of pixels corresponding to present column width> | white-space:wrap; width: value; white-space: normal |
Shrink to fit | None | mso-text-control: shrinktofit |
Merge cells horizontally | <TD COLSPAN=# of cells merged> | |
Merge cells vertically | <TD ROWSPAN=# of cells merged> |
When an HTML file is opened in Microsoft Excel, wordwrap is enabled for all imported cells. However, documents created in Excel have wordwrap disabled by default. The white-space: wrap style is therefore specified for cells that have wordwrap enabled.
The layout-flow and mso-rotate style attributes are used to specify text orientation and rotation.
The following styles are used to specify additional alignment properties used in international documents.
Horizontal alignment | Style |
Distributed | text-align:distributed |
Thai justify | text-align:thai-justify |
Right with indent | text-align:right; margin-right:ems |
Vertical alignment | Style |
Distributed | vertical-align:distributed |
Thai justify | vertical-align:thai-justify |
Orientation | Style |
Vertical text (no rotation) | layout-flow: vertical |
A style value other than auto must be used to specify auto color. If the string auto is specified as the color, unpredictable results can occur in different Web browsers. The following table shows the styles specified for different parts of a worksheet when the color is "auto."
Object | Styles | Color |
Background | mso-background-source:auto (the background color is not specified in the HTML file) | Not used in Microsoft Excel |
Border | border-left:1pt solid windowtext border-right:1pt solid windowtext border-top: 1pt solid windowtext border-bottom: 1pt solid windowtext |
Foreground color |
Font | color: windowtext | Auto font color |
Pattern | mso-pattern: .25gray windowtext | Foreground color |
The following table lists the basic font properties and how they are specified in HTML. Some characteristics, such as bold and italic, use both HTML and styles for compatibility with a wide variety of Web browsers. In general, cell formatting is specified only when it is different from the default formatting.
For the Spreadsheet component, the strikethrough, subscript, and superscript elements and styles are not supported.
Font property | HTML | Style |
Name | <FONT FACE="name of font"> | font-family:"name of font" |
Italic | <I> | font-style:italic |
Bold | <B> | font-weight:bold |
Regular | None | font-style:normal |
Size | <FONT SIZE="value from 1 to 7"> | font-size:ptsize |
Single underline | <U> | text-decoration: underline |
Double underline | <U> | text-decoration: underline; mso-text-underline: double |
Single accounting underline | <U> | text-decoration: underline; ms-text-underline: single-accounting |
Double accounting underline | <U> | text-decoration: underline; mso-text-underline: double-accounting |
Color | <FONT COLOR="name or rgb value"> | color: name, rgb value, or windowtext for auto color |
Normal font | None | TD {formatting from default cell style} |
Strikethrough | <STRIKE> | text-decoration:line-through |
Superscript | <SUP> | vertical-align:super |
Subscript | <SUB> | vertical-align:sub |
Outline (Macintosh only) | None | mso-text-effect: outline |
Shadow (Macintosh only) | None | text-shadow: auto |
The following table lists the color names and corresponding RGB values.
Color name | Excel color name | RGB value |
black | auto | none |
black | black | #000000 |
blue | blue | #0000ff |
aqua | turquoise | #00ffff |
lime | bright green | #00ff00 |
purple | pink | #ff00ff |
red | red | #ff0000 |
yellow | yellow | #ffff00 |
white | white | #ffffff |
navy | dark blue | #000080 |
teal | teal | #008080 |
green | green | #008000 |
fuchsia | violet | #800080 |
maroon | dark red | #800000 |
olive | dark yellow | #808000 |
silver | gray 25% | #c0c0c0 |
gray | gray 50% | #808080 |
The font-family style attribute is used to store additional information about the font. The font name is specified in quotation marks followed by a comma and the name of the generic font family without quotation marks. The mso-font-charset style attribute specifies the font number of the Windows character set.
To reduce file size, formatting that is applied to every cell, such as font color and size, is specified in style definitions. However, when the font color or size is different from the default color or size and the cell is not empty, the Font element is used for compatibility with Web browsers. The color attribute of the Font element specifies the font color, and the size attribute specifies the font size. The class attribute is also specified to preserve the other formatting properties. When the Web page is opened in Microsoft Excel and both HTML formatting elements and CSS styles are specified, the CSS styles are used to determine the cell formatting.
The following table lists the style attributes used to specify border formatting.
Border | Style attribute |
Top | border-top |
Bottom | border-bottom |
Diagonal, top right | mso-border-up |
Left | border-left |
Right | border-right |
Diagonal, top left | mso-border-down |
If the top, bottom, left, and right borders are visible and have the same line style and color, the border style attribute is used as a shorthand way to specify the border formatting.
For the Spreadsheet component, the diagonal border styles are not supported.
The border style attribute has 3 values: weight, style, and color.
Border style | Thickness (in lines) | Style |
None | 0 | border: none (default); when no borders are applied, only one value, none, is specified |
Thin | 1 | border: .5pt solid rgbcolor |
Medium | 2 | border: 1pt solid rgbcolor |
Dashed | 1 | border: .5pt dashed rgbcolor |
Dotted | 1 | border: .5pt dotted rgbcolor |
Thick | 3 | border: 1.5pt solid rgbcolor |
Double | 3 | border: 1.5pt double rgbcolor |
Hair | 1 | border: .5pt solid rgbcolor; border-style: hairline |
Medium dashed | 2 | border: 1pt dashed rgbcolor |
Dash-dot | 1 | border: .5pt dashed rgbcolor; border-style: dash-dot |
Medium dash-dot | 2 | border: 1pt dashed rgbcolor; border-style: dash-dot |
Dash-dot-dot | 1 | border: .5 dashed rgbcolor; border-style: dash-dot-dot |
Medium dash-dot-dot | 2 | border: 1pt dashed rgbcolor; border-style: dash-dot-dot |
Slanted dash dot | 2 | border: 1pt dashed rgbcolor; border-style:slanted-dash-dot |
When two borders are applied to the same line, the style of the last one mentioned is used. In some Web browsers, the border appears twice as thick since both are represented. To work around this problem, cell styles are specified to hide the borders. In the following example, the top and left borders are hidden when they overlap other borders.
style='border-top: none; border-left: none'
The following table lists the border style applied by Microsoft Excel when values other than the ones listed in the previous table are encountered.
Border style | Border weight | Border style applied |
Solid | weight < 1pt | Thin |
Solid | 1pt <= weight < 1.5pt | Medium |
Solid | 1.5pt <= weight | Thick |
Hairline | Any | Hairline |
Dashed | weight < 1pt | Dashed |
Dashed | 1pt <= weight | Medium dashed |
Double | Any | Double |
Dotted | Any | Dotted |
Dash-dot | weight < 1pt | Dash-dot |
Dash-dot | 1pt <= weight | Medium dash-dot |
Dash-dot-dot | weight < 1pt | Dash-dot-dot |
Dash-dot-dot | 1pt <= weight | Medium dash-dot-dot |
Slanted-dash-dot | Any | Slanted-dash-dot |
Triple | Any | Double |
Unused style | 0-1.0pt | Thin |
Unused style | 1.1-1.5pt | Medium |
Unused style | Over 1.5pt | Thick |
Tables are saved with a white background by default. The bgcolor attribute of the Body, TD, and TR elements specifies the color. The background color can be changed, but the color setting is ignored when the page is opened in a Microsoft Office program. The background style attribute is also used to specify the background color using either the color name or hexadecimal RGB value. For TR elements that specify a style class with a background style, the color is not always inherited by the TD elements contained in the row.
For the Spreadsheet component, only solid pattern colors are supported, and the mso-foreground style is not supported.
The mso-pattern style attribute has 2 values specifying the pattern style and its color. The following table lists the pattern names that can be used to specify the pattern style.
Pattern | Excel pattern name |
Solid (default) | auto |
75% gray | 75-gray |
50% gray | 50-gray |
25% gray | 25-gray |
12.5% gray | 125-gray |
6.25% gray | 0625-gray |
Horizontal stripe | horz-stripe |
Vertical stripe | vert-stripe |
Reverse diagonal stripe | reverse-diag-stripe |
Diagonal stripe | diag-stripe |
Diagonal crosshatch | diag-cross |
Thick diagonal crosshatch | thick-diag-cross |
Thin horizontal stripe | thin-horz-stripe |
Thin vertical stripe | thin-vert-stripe |
Thin reverse diagonal stripe | thin-reverse-diag-stripe |
Thin diagonal stripe | thin-diag-stripe |
Thin horizontal crosshatch | thin-horz-cross |
Thin diagonal crosshatch | thin-diag-cross |
When a page containing Microsoft Word patterns is opened, the patterns are converted to the closest equivalent pattern in Microsoft Excel. The following table lists the equivalent patterns.
Pattern | Word pattern name | Excel pattern equivalent |
2.5% | 25-gray | 6.25-gray |
5% | 5-gray | 6.25-gray |
7.5% | 075-gray | 6.25-gray |
10% | 10-gray | 12.5-gray |
12.5% | 12.5-gray | 12.5-gray |
15% | 15-gray | 12.5-gray |
17.5% | 175-gray | 12.5-gray |
20% | 20-gray | 25-gray |
22.5% | 225-gray | 25-gray |
25% | 25-gray | 25-gray |
27.5% | 275-gray | 25-gray |
30% | 30-gray | 25-gray |
32.5% | 325-gray | 25-gray |
35% | 35-gray | 25-gray |
37.5% | 37.5-gray | 25-gray |
40% | 40-gray | 50-gray |
42.5% | 425-gray | 50-gray |
45% | 45-gray | 50-gray |
47.5% | 475-gray | 50-gray |
50% | 50-gray | 50-gray |
52.5% | 525-gray | 50-gray |
55% | 55-gray | 50-gray |
57.5% | 575-gray | 50-gray |
60% | 60-gray | 50-gray |
62.5% | 625-gray | 50-gray |
65% | 65-gray | 75-gray |
67.5% | 675-gray | 75-gray |
70% | 70-gray | 75-gray |
72.5% | 725-gray | 75-gray |
75% | 75-gray | 75-gray |
77.5% | 775-gray | 75-gray |
80% | 80-gray | 75-gray |
82.5% | 825-gray | 75-gray |
85% | 85-gray | 75-gray |
87.5% | 87.5-gray | 75-gray |
90% | 90-gray | 75-gray |
92.5% | 925-gray | 75-gray |
95% | 95-gray | 75-gray |
97% | 97-gray | 75-gray |
97.5% | 975-gray | 75-gray |