Introduction

Beyond creating and styling workbooks, most day-to-day spreadsheet code spends its time reading and writing cell values, attaching formulas, and moving data between XLSX and CSV. Aspose.Cells FOSS for Go covers all three through the Workbook and Cells types.

The library is available as a Go module at github.com/aspose-cells-foss/Aspose.Cells-FOSS-for-Go and is released under the MIT license. Install it with go get github.com/aspose-cells-foss/Aspose.Cells-FOSS-for-Go/v26 into any Go 1.24+ project.

This post walks through cell read/write, formulas, CSV conversion, and cell removal.


Key Features

Create a Workbook and Write Cells

NewWorkbook() returns a workbook with one worksheet already present. Write values with Cells().Set(ref, value):

wb := cells_foss.NewWorkbook()
ws := wb.Worksheets[0]

ws.Cells().Set("A1", "Item")
ws.Cells().Set("B1", "Category")
ws.Cells().Set("C1", "Price")
ws.Cells().Set("A2", "Widget A")
ws.Cells().Set("B2", "Gadgets")
ws.Cells().Set("C2", 12.99)

wb.Save("inventory.xlsx")

Read Cells Back

Cells().Get(ref) returns the *Cell for a reference along with an error if the reference is invalid:

wb := cells_foss.NewWorkbook()
ws := wb.Worksheets[0]
ws.Cells().Set("C2", 12.99)

cell, err := ws.Cells().Get("C2")
if err != nil {
	fmt.Printf("Error: %v\n", err)
	return
}
fmt.Printf("C2 = %v\n", cell.Value)

Use Cells().All() to enumerate every populated cell in the collection when you need to iterate over the whole sheet.

Add a Formula

Cell.SetFormula stores a formula string on a cell. Create the cell first with Set, then attach the formula — the formula is evaluated by Excel or LibreOffice on open, not by the library:

wb := cells_foss.NewWorkbook()
ws := wb.Worksheets[0]

ws.Cells().Set("D2", nil)
cell, _ := ws.Cells().Get("D2")
cell.SetFormula("C2*2")

CSV Conversion

Workbook.ExportToCSV writes a given worksheet index to a CSV file with the delimiter of your choice; Workbook.ImportFromCSV reads a CSV file into a named worksheet:

wb := cells_foss.NewWorkbook()

if err := wb.ExportToCSV(0, "inventory.csv", ','); err != nil {
	fmt.Printf("Error exporting: %v\n", err)
	return
}

Remove a Cell

Cells().Remove(ref) clears a cell’s value:

wb := cells_foss.NewWorkbook()
ws := wb.Worksheets[0]
ws.Cells().Set("A2", "Widget A")

if err := ws.Cells().Remove("A2"); err != nil {
	fmt.Printf("Error removing cell: %v\n", err)
}

Quick Start

Install the module:

go get github.com/aspose-cells-foss/Aspose.Cells-FOSS-for-Go/v26

A minimal workflow — build a small table of values and export it to CSV:

package main

import (
	"fmt"

	cells_foss "github.com/aspose-cells-foss/Aspose.Cells-FOSS-for-Go/v26/aspose/cells_foss"
)

func main() {
	wb := cells_foss.NewWorkbook()
	ws := wb.Worksheets[0]

	ws.Cells().Set("A1", "Item")
	ws.Cells().Set("B1", "Price")
	ws.Cells().Set("A2", "Widget A")
	ws.Cells().Set("B2", 12.99)

	if err := wb.ExportToCSV(0, "inventory.csv", ','); err != nil {
		fmt.Printf("Error exporting: %v\n", err)
		return
	}
	fmt.Println("Exported inventory.csv")
}

Supported Formats

FormatExtensionReadWrite
XLSX.xlsx
CSV.csv

XLSX workbooks are built in memory with NewWorkbook and written with Workbook.Save. CSV is bidirectional via Workbook.ImportFromCSV and Workbook.ExportToCSV.


Open Source & Licensing

Aspose.Cells FOSS for Go is released under the MIT license. There are no usage restrictions, no runtime fees, and no registration requirements. The source code is available at github.com/aspose-cells-foss/Aspose.Cells-FOSS-for-Go.

Commercial use is permitted under the MIT license terms. If your project requires enterprise-grade support, extended format coverage, or cloud integration, the Aspose.Cells — Enterprise Product Family is a separate commercial offering.


Getting Started