XLSXLibExcel files for Ring

ExcelWriter

The class that builds a workbook: sheets, cells, styles, merged cells, filters, frozen panes, images and saving.

ExcelWriter Class#

Constructor#

Ring
excel = new ExcelWriter()

Creates a new Excel workbook.

Document Properties#

MethodDescription
setAuthor(author)Set document author
setTitle(title)Set document title
setCompany(company)Set company name

Example:

Ring
excel.setAuthor("John Doe")
excel.setTitle("Sales Report 2025")
excel.setCompany("ABC Corporation")

Sheet Management#

MethodDescription
addSheet(name)Add a new worksheet
selectSheet(index)Select sheet by index (1-based)
selectSheetByName(name)Select sheet by name
getSheetCount()Get number of sheets

Example:

Ring
excel.addSheet("Sales")
excel.addSheet("Expenses")
excel.selectSheet(1)        # Select first sheet
excel.selectSheetByName("Expenses")  # Select by name
? excel.getSheetCount()     # Output: 2

Cell Operations#

MethodDescription
setCell(row, col, value)Set cell value (auto-detects type)
setCellWithStyle(row, col, value, styleId)Set cell with specific style
setFormula(row, col, formula)Set cell formula (without =)
setNumber(row, col, value)Set numeric value
setDate(row, col, year, month, day)Set date value

Example:

Ring
excel.setCell(1, 1, "Text")          # String
excel.setCell(1, 2, 42)              # Number
excel.setCell(1, 3, 3.14159)         # Decimal
excel.setFormula(1, 4, "A1&B1")      # Formula (without =)
excel.setFormula(2, 1, "SUM(A1:C1)") # Sum formula
excel.setDate(3, 1, 2025, 12, 25)    # Date

Bulk Data Operations#

MethodDescription
exportList(data, startRow, startCol, hasHeader)Export 2D list to cells
setRow(row, values, startCol)Set entire row
setColumn(col, values, startRow)Set entire column

Example:

Ring
# Export a 2D list with header formatting
data = [
    ["Name", "Score"],
    ["Alice", 95],
    ["Bob", 87]
]
excel.exportList(data, 1, 1, true)  # true = first row is header

# Set a row of values
excel.setRow(5, ["Total", 182], 1)

# Set a column of values
excel.setColumn(3, ["A", "B", "C"], 1)

Styling#

Creating Styles#

Ring
styleId = excel.createStyle(options)

Available Options:

OptionTypeDescription
:boldBooleanBold text
:italicBooleanItalic text
:fontNameStringFont name (e.g., "Arial")
:fontSizeNumberFont size in points
:fontColorStringFont color (name or hex)
:bgColorStringBackground color (name or hex)
:alignStringHorizontal alignment: "left", "center", "right"
:valignStringVertical alignment: "top", "center", "bottom"
:wrapBooleanWrap text in cell
:borderStringBorder style (see below)
:borderColorStringBorder color (name or hex)
:numberFormatNumberNumber format ID (see constants)

Example:

Ring
# Create a custom style
myStyle = excel.createStyle([
    :bold = true,
    :italic = true,
    :fontName = "Arial",
    :fontSize = 14,
    :fontColor = "FF0000",
    :bgColor = "FFFF00",
    :align = "center",
    :valign = "center",
    :wrap = true,
    :border = "thin",
    :borderColor = "000000"
])

excel.setCellWithStyle(1, 1, "Styled Cell", myStyle)

Pre-defined Style Methods#

MethodDescription
createHeaderStyle()Blue background, white bold text, centered
createCurrencyStyle()Currency number format
createPercentageStyle()Percentage number format
createDateStyle()Date number format

Example:

Ring
headerStyle = excel.createHeaderStyle()
currencyStyle = excel.createCurrencyStyle()

excel.setCellWithStyle(1, 1, "Price", headerStyle)
excel.setCellWithStyle(2, 1, 99.99, currencyStyle)

Column and Row Formatting#

MethodDescription
setColumnWidth(col, width)Set column width (in characters)
setRowHeight(row, height)Set row height (in points)
autoFitColumn(col)Auto-fit column width (approximate)

Example:

Ring
excel.setColumnWidth(1, 20)   # Column A = 20 characters wide
excel.setColumnWidth(2, 15)   # Column B = 15 characters wide
excel.setRowHeight(1, 30)     # Row 1 = 30 points tall

Merged Cells#

Ring
excel.mergeCells(row1, col1, row2, col2)

Merges cells from (row1, col1) to (row2, col2).

Example:

Ring
excel.setCell(1, 1, "Title")
excel.mergeCells(1, 1, 1, 4)  # Merge A1:D1

excel.setCell(3, 1, "Subtitle")
excel.mergeCells(3, 1, 5, 1)  # Merge A3:A5 (vertical)

Auto Filter#

Ring
excel.setAutoFilter(row1, col1, row2, col2)

Adds filter dropdowns to the specified range.

Example:

Ring
# Add headers and data rows...
# Enable filter on the data range
excel.setAutoFilter(1, 1, 10, 3)  # A1:C10

Freeze Panes#

MethodDescription
freezePanes(row, col)Freeze above row and left of column
freezeTopRow()Freeze first row only
freezeFirstColumn()Freeze first column only

Example:

Ring
excel.freezeTopRow()        # Freeze row 1
excel.freezeFirstColumn()   # Freeze column A
excel.freezePanes(2, 2)     # Freeze row 1 AND column A

Images#

Ring
excel.addImage(imagePath, row, col, width, height)

Parameters:

Example:

Ring
excel.addImage("logo.png", 1, 1, 4, 3)      # A1, 4 cells wide, 3 cells tall
excel.addImage("chart.jpg", 10, 1, 8, 6)    # A10, 8x6 cells

Supported Formats: PNG, JPG, JPEG, BMP, GIF

Saving#

Ring
result = excel.save(filename)

Returns true if successful, false otherwise.

XLSXLib - Excel files for Ring, made with ringdoc.