Feature Overview
Feature Overview
Aspose.Cells FOSS for Go’s API centers on Workbook, Worksheet, Cells, and Cell. This guide walks through the library’s other capabilities: styling, data validation, tables, pictures, and streaming reads for large files.
Cell Styling
Group Font, Fill, Alignment, and Border settings into a reusable Style, then apply it to a cell with Cell.SetStyle:
wb := cells_foss.NewWorkbook()
ws := wb.Worksheets[0]
boldStyle := cells_foss.NewStyle()
boldStyle.Font.Bold = true
boldStyle.Font.Size = 12
highlightStyle := cells_foss.NewStyle()
highlightStyle.Font.Color = "FFFFFFFF"
highlightStyle.Font.Bold = true
highlightStyle.Fill = &cells_foss.Fill{
Type: cells_foss.FillTypeSolid,
Color: "FF4472C4",
}
cell, _ := ws.Cells().Get("A1")
cell.SetStyle(boldStyle)Alignment controls Horizontal, Vertical, and WrapText; Border controls the Top, Bottom, Left, and Right rule visibility plus Color.
Data Validation
Worksheet.AddDataValidation attaches a validation rule to a cell range. The DataValidation struct carries the rule Type, one or two Formula values, and error-message fields:
wb := cells_foss.NewWorkbook()
ws := wb.Worksheets[0]
dv := &cells_foss.DataValidation{
Type: cells_foss.DataValidationTypeList,
Formula1: `"Apple,Banana,Cherry,Dragonfruit"`,
AllowBlank: true,
ShowErrorMessage: true,
ErrorTitle: "Invalid Fruit",
ErrorMessage: "Please pick a fruit from the list.",
ErrorStyle: cells_foss.ErrorStyleStop,
}
ws.AddDataValidation("A2:A10", dv)A whole-number range validation uses DataValidationTypeWhole with Formula1/Formula2 as the lower and upper bounds.
Tables
Worksheet.AddTable creates a structured Table over a range, with an optional header row and a named table style:
wb := cells_foss.NewWorkbook()
ws := wb.Worksheets[0]
tbl := ws.AddTable("A1:F6")
tbl.HasHeaderRow = true
tbl.StyleName = "TableStyleMedium6"Retrieve an existing table by name with Worksheet.GetTable(name).
Pictures
Worksheet.AddPicture embeds an image; Picture.SetAnchor(row, col) positions it:
wb := cells_foss.NewWorkbook()
ws := wb.Worksheets[0]
imageBytes := []byte{} // populate with real image bytes before use
pic := &cells_foss.Picture{Data: imageBytes, Format: "png"}
ws.AddPicture(pic)
pic.SetAnchor(5, 0)Streaming Large Files
StreamingReader reads a worksheet row by row through a callback, so a multi-thousand-row workbook never has to be fully loaded into memory:
path := "outputfiles/large_workbook.xlsx"
sr := cells_foss.NewStreamingReader(path)
err := sr.ProcessRows("Sheet1", func(rowIdx int, cells map[string]string) error {
// process one row at a time
return nil
})
if err != nil {
fmt.Printf("Error streaming: %v\n", err)
}Tips and Best Practices
- Use
StreamingReaderinstead of a fullWorkbookload when a file may have thousands of rows and you only need to read, not modify, it. - Build a
Styleonce and reuse it across many cells rather than constructing a new one per cell. Cell.SetFormulastores a formula string verbatim — it is evaluated by Excel or LibreOffice on open, not by the library at save time.- Check the
errorreturn value fromSave,AddDataValidation, and CSV import/export calls — spreadsheet I/O can fail on invalid paths or malformed input.
Common Issues
| Issue | Cause | Fix |
|---|---|---|
Cell value not visible after Set | Referencing the wrong sheet or an out-of-range cell reference | Confirm the Worksheet index and that the A1-style reference matches the intended cell |
| Formula shows as raw text instead of computing | The library only stores the formula string; it does not evaluate formulas | Open the file in Excel or LibreOffice, which perform the calculation on open |
| Data validation not visible in Excel | Validation was added to a range that does not include the target cell | Confirm the range string (e.g. "A2:A10") covers the cells you expect to validate |
FAQ
Does the library evaluate formulas itself?
No. Cell.SetFormula/GetFormula store a formula string that Excel or LibreOffice evaluates when the file is opened.
Can I stream-write large workbooks, not just stream-read them?
StreamingReader covers streaming reads. Writing large workbooks currently goes through the standard in-memory Workbook/Worksheet API.
Does AddTable apply an auto-filter automatically?
This is not confirmed in the current API surface — only HasHeaderRow and StyleName are documented Table fields. Verify against the generated .xlsx file if this matters for your use case.
API Reference Summary
| Class / Method | Description |
|---|---|
Workbook.NewWorkbook / Save | Create and save a workbook |
Worksheet.Cells | Access the cell collection for a worksheet |
Cells.Get / Set / Remove / All | Read, write, remove, and enumerate cells |
Cell.SetStyle / SetFormula / GetFormula | Apply styling and formulas to a cell |
Style, Font, Fill, Alignment, Border | Compose reusable cell formatting |
Worksheet.AddDataValidation | Attach a validation rule to a cell range |
Worksheet.AddTable / GetTable | Create and retrieve structured table ranges |
Worksheet.AddPicture / Picture.SetAnchor(row, col) | Embed and position images |
StreamingReader.ProcessRows | Stream a worksheet row by row |
Workbook.ExportToCSV / ImportFromCSV | Convert between XLSX and CSV |
Workbook.SetPassword / VerifyPassword | Protect and check a workbook password |