DocRaptor Home

Excel Reference

How to make an Excel file with DocRaptor

Excel Documents

To make an Excel file with DocRaptor, your document content should only contain tables and be formatted as XML, not HTML.

Here is an example of a basic, single worksheet file. CSS is used to style cells, rows, and the entire table using inline style attributes.

<table name="Example Worksheet">
  <tr style="font-size: 16px">
    <td colspan="2">Big Row</td>
  </tr>
  <tr>
    <td style="color: blue">Blue Cell</td>
    <td style="-xls-format:currency_dollar">1000</td>
  </tr>
</table>

DocRaptor doesn't support writing CSS <style> blocks.

Multiple Worksheets

To make an XLS file with more than one worksheet, just send multiple tables, wrapped in a <tables> tag. With the following input:

<tables>
  <table name="Dino Scale">
    ...
  </table>
  <table name="Dino Budget">
    ...
  </table>
</tables>

This will be your output:

Multiple worksheets

Data Formatting: numbers, currency, dates

You can use the special -xls-format to set the format (number, currency, etc). An example is below, but refer to formatting options below for all the options.

<table>
  <tr>
    <td style="-xls-format:currency_dollar">1000</td>
    <td style="-xls-format:currency_pound">1000</td>
  </tr>
  <tr>
    <td style="-xls-format:float">100.012</td>
    <td style="-xls-format:date_format1">09/23/21</td>
  </tr>
</table>

Merged Cells

To merge cells, set colspan and rowspan attributes on <td> elements:

Special attributes
<table>
  <tr>
    <td colspan="2">Foo</td>
  </tr>
  <tr>
    <td rowspan="2">Bar</td>
    <td>Baz</td>
  </tr>
  <tr>
    <td>foobar</td>
  </tr>
</table>

Worksheet Name & Password

Set the name attribute on a table element to name the sheet produced by the table.

Set the password attribute on a table element to password protect the worksheet produced by the table with the given password. By default this means that all cells in the worksheet will be read-only, unless the password is entered. You can control what cells will be read-only using the -xls-locked style.

Styling Options

DocRaptor supports many CSS style attributes you're already familiar with, plus a few Excel file specific attributes. Here is a complete list of supported attributes.

-xls-content-type

inline-style only

Options:
auto
string
number
formula
datetime
boolean
blank

The content type for the cell in Excel. Auto will try and determine the Excel cell type automatically based off the cell contents. To keep leading zeros, use string. To change the formatting of the content, see -xls-format.

-xls-format

inline-style only

Numbers & Text Options:
default
text
integer
float
percent float
percent integer
accounting float
accounting integer
accounting red float
accounting red integer
exponential
fraction_one_digit
fraction_two_digits
thousands_float
thousands_integer
Currency Options:
currency_dollar
currency_euro_prefix
currency_float_euro_prefix
currency_euro_suffix
currency_japanese_yen
currency_pound
Dates & Times Options:
date_format1 (m/d/yy)
date_format2 (d-mmm-yy)
date_format3 (d-mmm)
date_format4 (mmm-yy)
date_format5 (h:mm AM/PM)
date_format6 (h:mm:ss AM/PM)
date_format7 (h:mm)
date_format8 (h:mm:ss)
date_format9 (m/d/yy h:mm)
date_format10 (d/m/yy)
date_format11 (d/m/yy h:mm:ss)
date_format12 (dd.MM.yyyy)

Sets the format for the cell content. If you use a number format on a text or date cell, the results may be unpredictable.

-xls-thousands-delimiter

inline-style only

Options:
,

The character that delimits large numbers (i.e. 1 million written as ‘1,000,000’ is delimited by the comma character). If you are using this, you may want to set ‘-xls-decimal-delimiter’, too.

-xls-decimal-delimiter

inline-style only

Options:
.

The character that delimits the begin of the decimal portion of numbers (i.e. 11/10 written as 1.1 is delimited by the period character). If you are using this, you may want to set ‘-xls-thousands-delimiter’, too.

color

inline-style only

Options:
black

Sets the text color for the cell. Can take any named web color or hex value.

Hex values will be translated to the closest of the valid colors for Excel.

font-size

inline-style only

Options:
10

Sets the font size in points.

font-family

inline-style only

Options:
Arial

Sets the font family.

font-style

inline-style only

Options:
normal
italic

Sets if the font should be italic or not.

font-weight

inline-style only

Options:
normal
bold
bolder
lighter
100
200
300
400
500
600
700
800
900

Sets the weight of the font.

text-decoration

inline-style only

Options:
none
line-through
underline

Sets the text decoration.

text-align

inline-style only

Options:
general
left
right
center
justify
fill

The horizontal alignment for cell content.

vertical-align

inline-style only

Options:
bottom
top
center
justify

The vertical alignment for cell content.

text-indent

inline-style only

Options:
0
...
14

Amount of indentation of the cell content. Integer value from 0 to 14.

white-space

inline-style only

Options:
nowrap
wrap

Cell content wrapping. If set to wrap, then Excel will wrap data in cells with this format so that it fits within the cell boundaries.

-xls-text-orientation

inline-style only

Options:
horizontal
vertical
stacked
0
45
90
270
315
360

Sets the text orientation for this cell. Arbitrary values are not allowed.

-xls-background-pattern

inline-style only

Options:
none
solid
horizontal stripe
vertical stripe
reverse diagonal stripe
diagonal stripe
diagonal crosshatch
thick diagonal crosshatch
thin horizontal stripe
thin vertical stripe
thin reverse diagonal stripe
thin diagonal stripe
thin horizontal crosshatch
thin diagonal crosshatch
6.25%
12.5%
25%
50%
75%

Sets the background pattern. If background-color is set, solid is the default.

background-color

inline-style only

Options:
transparent
or any of Valid Color Options

Sets the background color for the cell. Can take any named web color or hex value. If -xls-background-pattern is set, grey is the default.

Hex values will be translated to the closest of the valid colors for Excel. Certain colors (such as black) will cause Excel to ignore the background pattern you set.

Options:
transparent
or any of Valid Color Options

Sets the border color for the cell. Can take any named web color or hex value. If border-*-style is set, black is the default.

Hex values will be translated to the closest of the valid colors for Excel.

Options:
none
thin
medium
dashed
dotted
thick
double
hair
medium dashed
dash dot
medium dash dot
dash dot dot
medium dash dot dot
slanted dash dot

Sets the border style (lines that appear around a cell). If border-*-color is set, thin is the default.

Height & Width

height

inline-style only

Options:
auto

Sets the height of a row, in points. Only valid on <tr> elements.

width

inline-style only

Options:
auto
1
...
255

Sets the width of a column, in number of characters. The last width specified for a column wins (i.e., if you specify the width for a column in both row 1 and row 2, the width specified in row 2 is used).

-xls-locked

inline-style only

Options:
true
false

Sets if this cell is locked. Only has meaning if a password has been set for the sheet that will contain this cell.

-xls-frozen-row

inline-style only

Options:
true
false

Set this style option with a value of true on contiguous tr elements to freeze those rows to the top of the spreadsheet.

Note you must set this option on the first tr in your HTML.

-xls-frozen-column

inline-style only

Options:
true
false

Set this style option with a value of true on contiguous th and td elements to freeze those rows to the left side of the spreadsheet.

Note you must set this option on the first th or td in your HTML.

Character Escaping

Excel documents must be written in XML, not HTML. XML has strict escaping requirements for text content:

  • Ampersands (&) should be &amp;
  • Quotation marks (") should be &quot;
  • Apostrophes (') should be &apos;
  • Less than (<) should be &lt;
  • Greater than (>) should be &gt;

Ready to get started? Try DocRaptor for free with unlimited test documents.