Standard library · Encoding and data

excel

Reading and writing Excel spreadsheets (xlsx and xls), OpenDocument (ods) and CSV.

import excel

A workbook holds several sheets, and each sheet holds cells by row and column, from zero. Turn Excel references such as C5 into a row and column with CellRef and ParseCellRef.

Open and Save work the format out from the file extension. Formulas are stored and read with their last calculated result, but Salam does not evaluate a formula itself.

Types

Style

struct Style
The style of a cell.
NameTypeDescription
boldbool = falseBold.
italicbool = falseItalic.
underlinebool = falseUnderlined.
font_namestr = "Calibri"The font name.
font_sizeint = 11The font size.
font_colorstr = ""The text colour as hex, such as FF0000.
bg_colorstr = ""The background colour.
align_hint = 0The horizontal alignment.
align_vint = 0The vertical alignment.
num_formatstr = ""The number display format, such as 0.00.
excel-Cell.salam
import excel

func main:
    println excel.ColumnLabel(0), excel.ColumnLabel(25), excel.ColumnLabel(26), excel.ColumnLabel(703)
    println excel.ColumnIndex("A"), excel.ColumnIndex("AA"), excel.CellRef(4, 2)
    mut row := 0
    mut col := 0
    println excel.ParseCellRef("C5", row, col), row, col, excel.ParseCellRef("5C", row, col)
    serial := excel.EpochToSerial(0)
    println serial, excel.SerialToEpoch(45371.0)
    text := excel.NewStringCell(0, 0, "some text")
    number := excel.NewNumberCell(0, 1, 3.5)
    flag := excel.NewBoolCell(0, 2, false)
    date := excel.NewDateCell(0, 3, 0)
    formula := excel.NewFormulaCell(0, 4, "A1*2", 7.0)
    println text.kind == excel.CellString, number.num, flag.flag, date.kind == excel.CellDate, formula.formula, formula.num
    println excel.CellEmpty, excel.CellNumber, excel.CellBool, excel.CellFormula
    mut styles := excel.NewStyleSheet()
    bold := excel.Style { bold = true, bg_color = "FFFF00", align_h = excel.AlignCenter }
    id := styles.get_or_add(bold)
    println id, styles.get_or_add(bold) == id, styles.count(), styles.get(id).bold
    println bold.equals(styles.get(id)), bold.font_name, bold.font_size
    println excel.AlignDefault, excel.AlignLeft, excel.AlignRight, excel.AlignTop, excel.AlignMiddle, excel.AlignBottom
    styles.free()
end
OutputA Z AA AAB 0 26 C5 true 4 2 false 25569 1710892800 true 3.5 false true A1*2 7 0 2 3 5 1 true 2 true true Calibri 11 0 1 3 1 2 3

equals

func equals(other: Style): bool
True when two styles are the same.

The example for this item is shown with the ones above: excel-Cell.salam

StyleSheet

struct StyleSheet
The table of unique styles.
NameTypeDescription
stylesVector