Skip to content
Google Go (golang) library for reading and writing XLSX files.
Go Shell
Branch: master
Clone or download
ShawnMilo Merge pull request #511 from alex/patch-1
Fixed an apparent typo in a comment
Latest commit 426ebfe Dec 17, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
testdocs Merge branch 'hyperlinks' of github.com:elimity-com/xlsx into elimity… Oct 30, 2019
.gitignore Merge branch 'hyperlinks' of github.com:elimity-com/xlsx into elimity… Oct 30, 2019
.travis.yml Disable Fuzz regression Nov 4, 2019
AUTHORS.txt Added an AUTHORS.txt file. Apr 1, 2016
CODE_OF_CONDUCT.md Create CODE_OF_CONDUCT.md Aug 22, 2017
LICENSE Insert the license in the code base. Aug 22, 2017
README.org Convert markdown link to Org (doh!) Oct 10, 2019
cell.go Merge branch 'hyperlinks' of github.com:elimity-com/xlsx into elimity… Oct 30, 2019
cell_test.go 'WriteWithDefaultCellType' writes all cells in a column as the defaul… Aug 2, 2019
col.go Custom number formats. Nov 3, 2019
col_test.go gofmt Oct 10, 2019
common_test.go go fmt Jul 21, 2014
compatibility_test.go
data_validation.go Disassociate CellMetadata, StreamStyle and DefaultCellType from Col Oct 10, 2019
data_validation_test.go Disassociate CellMetadata, StreamStyle and DefaultCellType from Col Oct 10, 2019
date.go gofmt Oct 10, 2019
date_test.go Handle dates in further than time.Duration Jun 26, 2018
doc.go Make a minor update to the docs Oct 31, 2014
example_read_test.go Remove else branch in example_read_test when code panic Mar 2, 2018
file.go Fix-up tests Oct 30, 2019
file_test.go Fix-up tests Oct 30, 2019
format_code.go Most of the tests are passing Oct 8, 2019
format_code_test.go Improve Cell Fromatting Oct 17, 2017
fuzz.go Define fuzzing target Aug 24, 2019
fuzzit.sh Only fail Fuzzit on missing API key if this isn't a pull request Nov 4, 2019
fuzzy_test.go gofmt -s -w . Mar 9, 2016
go.mod
go.sum Most of the tests are passing Oct 8, 2019
hsl.go Initial support for themes Mar 15, 2015
lib.go Merge branch 'hyperlinks' of github.com:elimity-com/xlsx into elimity… Oct 30, 2019
lib_test.go Merge branch 'hyperlinks' of github.com:elimity-com/xlsx into elimity… Oct 30, 2019
read.go Use FormattedValue instead of String Jul 14, 2017
read_test.go
reftable.go Fixed an apparent typo in a comment Dec 17, 2019
reftable_test.go Don't indent marshalled XML. Dec 10, 2014
row.go Most of the tests are passing Oct 8, 2019
row_test.go
sheet.go fixes Oct 30, 2019
sheet_test.go Fix-up tests Oct 30, 2019
stream_cell.go Comments Apr 15, 2019
stream_file.go Merge cells. Nov 3, 2019
stream_file_builder.go Custom number formats. Nov 3, 2019
stream_file_builder_test.go Most of the tests are passing Oct 8, 2019
stream_style.go Disassociate CellMetadata, StreamStyle and DefaultCellType from Col Oct 10, 2019
stream_style_test.go Custom number formats. Nov 3, 2019
stream_test.go Merge cells. Nov 3, 2019
style.go update Apr 15, 2019
style_test.go Reflect changes to default fill Oct 29, 2019
templates.go Remove font warning from Apple Numbers Apr 3, 2019
theme.go gofmt Apr 18, 2015
theme_test.go Initial support for themes Mar 15, 2015
write.go gofmt Oct 10, 2019
write_test.go write_test.go: repaired composite literal Oct 26, 2018
xmlContentTypes.go add theme1.xml ref to ContentTypes Feb 3, 2015
xmlContentTypes_test.go add theme1.xml ref to ContentTypes Feb 3, 2015
xmlSharedStrings.go Split sharedstrings.go and renamed to reftable.go and xmlSharedString… Nov 1, 2014
xmlSharedStrings_test.go Split sharedstrings.go and renamed to reftable.go and xmlSharedString… Nov 1, 2014
xmlStyle.go Custom number formats. Nov 3, 2019
xmlStyle_test.go Revise style defaults to match Excel's current expectations Oct 28, 2019
xmlTheme.go Initial support for themes Mar 15, 2015
xmlWorkbook.go Make sure CellsMap is initialised and populated where necessary Oct 19, 2019
xmlWorkbook_test.go added DefinedNames to the file struct by looping over defined names i… Nov 29, 2015
xmlWorksheet.go fixes Oct 30, 2019
xmlWorksheet_test.go Make sure CellsMap is initialised and populated where necessary Oct 19, 2019

README.org

XLSX

https://img.shields.io/travis/tealeg/xlsx/master.svg?style=flat-square https://codecov.io/gh/tealeg/xlsx/branch/master/graph/badge.svg https://godoc.org/github.com/tealeg/xlsx?status.svg https://img.shields.io/badge/license-bsd-orange.svg

Introduction

xlsx is a library to simplify reading and writing the XML format used by recent version of Microsoft Excel in Go programs.

The support for writing XLSX files is currently extremely minimal. It will expand slowly, but in the meantime patches are welcome!

A note about versions

As of October 8th, 2019, I’ve branched off v1.x.x maintenance work from master. The master branch will now be moving towards a new 2.0.0 milestone that will include breaking changes in the API. The scope of these changes will include, but perhaps not be limited to, the way `Col` elements and `DataValidation` works, as these aspects have been built around incorrect models of the underlying XLSX format.

See the https://github.com/tealeg/xlsx/milestone/5 for details.

Full API docs

The full API docs can be viewed using go’s built in documentation tool, or online at godoc.org.

Basic Usage

Reading XLSX files

Here is a minimal example usage that will dump all cell data in a given XLSX file. A more complete example of this kind of functionality is contained in the XLSX2CSV program:

package main

import (
    "fmt"
    "github.com/tealeg/xlsx"
)

func main() {
    excelFileName := "/home/tealeg/foo.xlsx"
    xlFile, err := xlsx.OpenFile(excelFileName)
    if err != nil {
        ...
    }
    for _, sheet := range xlFile.Sheets {
        for _, row := range sheet.Rows {
            for _, cell := range row.Cells {
                text := cell.String()
                fmt.Printf("%s\n", text)
            }
        }
    }
}

Some additional information is available from the cell (for example, style information). For more details see the godoc output for this package.

Writing XLSX files

The following constitutes the bare minimum required to write an XLSX document.

package main

import (
    "fmt"
    "github.com/tealeg/xlsx"
)

func main() {
    var file *xlsx.File
    var sheet *xlsx.Sheet
    var row *xlsx.Row
    var cell *xlsx.Cell
    var err error

    file = xlsx.NewFile()
    sheet, err = file.AddSheet("Sheet1")
    if err != nil {
        fmt.Printf(err.Error())
    }
    row = sheet.AddRow()
    cell = row.AddCell()
    cell.Value = "I am a cell!"
    err = file.Save("MyXLSXFile.xlsx")
    if err != nil {
        fmt.Printf(err.Error())
    }
}

Contributing

We’re extremely happy to review pull requests. Please be patient, maintaining XLSX doesn’t pay anyone’s salary (to my knowledge).

If you’d like to propose a change please ensure the following:

Eat a peach - Geoff

You can’t perform that action at this time.