DOCXLibWord documents for Ring

Tables

Create tables, set options, merge cells, borders, rich cells and conditional formatting.

Tables#

Table Creation Methods#

MethodParametersDescription
addTable()data, optionsFull-featured table with all formatting options
addSimpleTable()dataPlain table with no header styling
addStyledTable()data, headerBg, evenBgQuick styled table with two colour parameters

Table Options#

OptionTypeDescription
:headerRowtrue/falseFirst row is a header: bold, coloured background
:headerBgColorStringHeader row background colour hex
:headerTextColorStringHeader text colour. Default: FFFFFF
:evenRowBgColorStringAlternating even-row background colour
:borderStyleString"single", "double", "dashed", "dotted", "none"
:borderColorStringBorder colour hex. Default: 000000
:colWidthsListColumn widths in cm, e.g. [2, 6, 3, 5.5]
:headerVAlignStringHeader vertical alignment: "top", "center", "bottom"
:cellVAlignStringBody cell vertical alignment
:repeatHeadertrue/falseRepeat header row on each page when the table spans pages
:rowHeightsListPer-row heights in cm — 0 means auto-size, e.g. [1.5, 0, 2.0]
:rowHRuleStringHeight rule for :rowHeights: "atLeast" (default) or "exact"
:fontSizeNumberFont size for all cells in points
:conditionalRulesListConditional cell formatting rules (see §6.5)
Ring
doc.addTable([
    ["ID", "Description",                  "Status",      "Owner" ],
    ["1",  "Design new dashboard",          "In Progress", "Ahmed" ],
    ["2",  "Fix login timeout on mobile",   "Done",        "Sara"  ],
    ["3",  "Write API documentation v2",    "Pending",     "Omar"  ]
], [
    :headerRow      = true,
    :borderStyle    = "single",
    :headerBgColor  = "1565C0",
    :evenRowBgColor = "E3F2FD",
    :headerVAlign   = "center",
    :cellVAlign     = "center",
    :colWidths      = [2, 6, 3, 5.5]
])

# Per-row heights — header 1.5 cm tall, rows 2 & 4 auto-height, row 3 is 2.5 cm
doc.addTable(data, [
    :headerRow  = true,
    :colWidths  = [5, 10],
    :rowHeights = [1.5, 0, 2.5, 0],
    :rowHRule   = "atLeast"
])

Rich Cell Content — WordCell#

For cells needing mixed formatting, images, lists, or cell spanning:

Ring
# Styled cell spanning 3 columns
titleCell = new WordCell()
titleCell.setText("Status Report", [:bold=true, :color="1E6BB5"])
titleCell.setBgColor("DEEAF1")
titleCell.setColSpan(3)
titleCell.setVerticalAlign("center")

# Row-spanning category cell
cat = new WordCell()
cat.addRun("Electronics", [:bold=true, :color="1565C0"])
cat.setRowSpan(3)
cat.setVerticalAlign("center")
cat.setAlign("center")
cat.setBgColor("E3F2FD")

# Convenience function: wordCell(text, options)
hdr = wordCell("Category", [:bold=true, :color="white", :bgColor="37474F"])
WordCell methodParametersDescription
setText()text, optionsSet main text with formatting options
addRun()text, optionsAppend an additional text run
addText()text, optionsAlias for addRun()
addCellBulletList()items, listIdAdd a bullet list inside the cell
addCellNumberedList()items, listIdAdd a numbered list inside the cell
addCellImage()path, widthCm, heightCmEmbed an image in the cell
addCellHyperlink()text, relIdAdd a hyperlink inside the cell
setBgColor()colorCell background colour hex
setColSpan()nMerge across n columns
setRowSpan()nMerge down n rows
setVerticalAlign()align"top", "center", "bottom"
setAlign()alignText alignment within the cell
setBorder()style, colorAll-sides border (legacy — prefer setBorderSide)
setBorderSide()side, style, color, sizePer-side border — see §6.4
setTopBorder()style, color, sizeTop edge only
setBottomBorder()style, color, sizeBottom edge only
setLeftBorder()style, color, sizeLeft edge only
setRightBorder()style, color, sizeRight edge only
setNoBorder()—Remove all borders from this cell
setTextDir()dirRotate cell text — see §6.4
setPadding()top, bot, left, rightCell padding in cm
setWidth()widthCmOverride cell width in cm
Note

Tip: Use wordCell(text, options) as a shorthand to create a WordCell with a single text run in one line.

Per-Side Cell Borders and Text Direction#

Per-side borders give each cell edge an independent style, colour, and weight. This makes it easy to build accent-left sidebars, coloured header underlines, and borderless inner cells with only outer rules showing.

Ring
# Left accent sidebar — only a thick teal left edge, everything else removed
sidebar = wordCell("Note", [])
sidebar.setLeftBorder("thick",  "1B998B", 16)
sidebar.setTopBorder("none",    NULL, NULL)
sidebar.setBottomBorder("none", NULL, NULL)
sidebar.setRightBorder("none",  NULL, NULL)

# Double outer box
boxed = wordCell("Total", [:bold=true])
boxed.setTopBorder("double",    "000000", 8)
boxed.setBottomBorder("double", "000000", 8)
boxed.setLeftBorder("double",   "000000", 8)
boxed.setRightBorder("double",  "000000", 8)

# Header cell with a thick coloured bottom accent only
hdr = wordCell("January", [:bold=true, :align="center"])
hdr.setBottomBorder("thick", "E94F37", 12)

setBorderSide(side, style, color, size) parameter values:

ParameterValues
side"top", "bottom", "left", "right", "insideH", "insideV"
style"single", "double", "dashed", "dotted", "thick", "none"
colorHex string, or NULL for auto
sizeEighths-of-a-point: 4=½pt, 8=1pt, 16=2pt, 24=3pt — or NULL for default

Text direction rotates the cell's text. Most commonly used for compact column headers in data tables where many narrow columns need rotated labels.

Ring
# Text reads upward (BTL) — saves horizontal space for many columns
colHdr = wordCell("January", [:bold=true, :align="center"])
colHdr.setTextDir("btLr")

# Text reads downward (TBR)
colHdr2 = wordCell("Q1 Target", [:bold=true])
colHdr2.setTextDir("tbRl")
setTextDir valueDescription
"btLr"Bottom-to-top: text rotated 90° CCW (reads upward)
"tbRl"Top-to-bottom: text rotated 90° CW (reads downward)
"lrTb"Normal horizontal (default — also clears a previous direction)

Conditional Table Formatting#

Conditional rules apply per-cell background colour, text colour, and bold weight based on the cell's value. Rules are evaluated in order; a later rule overrides an earlier one for the same cell. The header row is never subject to conditional formatting.

Pass rules via the :conditionalRules option in addTable():

Rule keyTypeDescription
:colNumber1-based column index to test; 0 = test all columns
:conditionString"lt", "lte", "gt", "gte", "eq", "neq", "between", "contains"
:valueNumber / StringThreshold or comparison value
:value2NumberUpper bound for "between"
:bgColorStringBackground colour hex applied when rule matches
:textColorStringText colour hex applied when rule matches (optional)
:boldtrue/falseBold weight applied when rule matches (optional)
Ring
doc.addTable(data, [
    :headerRow   = true,
    :borderStyle = "single",
    :colWidths   = [4, 3, 3],
    :conditionalRules = [
        # Column 2 negative values → red background
        [:col=2, :condition="lt",       :value=0,    :bgColor="FDECEA", :textColor="C00000"],
        # Column 2 high values → green background
        [:col=2, :condition="gte",      :value=90,   :bgColor="E2EFDA", :textColor="375623"],
        # Any column containing "FAIL" → yellow + bold
        [:col=0, :condition="contains", :value="FAIL", :bgColor="FFF2CC", :bold=true]
    ]
])
DOCXLib - Word documents for Ring, made with ringdoc.