Google Go (golang) library for reading and writing XLSX files.
Go
Latest commit 76c1f5d Feb 19, 2017 @tealeg committed on GitHub Merge pull request #280 from HeinOldewage/master
Fixed the datarace surrounding the channel.
Permalink
Failed to load latest commit information.
testdocs Make file.ToSlice() output an empty string when the cell value is an … Dec 7, 2016
.gitignore Make file.ToSlice() output an empty string when the cell value is an … Dec 7, 2016
.travis.yml update travis, add more badges to README and add support for codecov.io Jul 20, 2016
AUTHORS.txt Added an AUTHORS.txt file. Apr 1, 2016
README.org cell.String has two value. Dec 7, 2016
cell.go Update cell.go Feb 2, 2017
cell_test.go add test coverage for err in Cell.ToDate Nov 2, 2016
col.go Added basic grouping support. May 20, 2016
col_test.go Add hidden cell property and rudimentary column support Oct 10, 2014
common_test.go go fmt Jul 21, 2014
compatibility_test.go test fixes for issue 191 Mar 6, 2016
date.go fix fraction of day calculation, round nearest to 1us Aug 11, 2016
date_test.go fix up date relate tests Aug 11, 2016
doc.go Make a minor update to the docs Oct 31, 2014
file.go Merge pull request #272 from tokyis/master Feb 17, 2017
file_test.go Merge pull request #272 from tokyis/master Feb 17, 2017
fuzzy_test.go gofmt -s -w . Mar 9, 2016
hsl.go Initial support for themes Mar 15, 2015
lib.go Fixed the datarace surrounding the channel. This was done by moving the Feb 19, 2017
lib_test.go Expose GetCoordsFromCellIDString & GetCellIDStringFromCoords. Jan 6, 2017
reftable.go Split sharedstrings.go and renamed to reftable.go and xmlSharedString… Nov 1, 2014
reftable_test.go Don't indent marshalled XML. Dec 10, 2014
row.go Added basic grouping support. May 20, 2016
row_test.go Make AddSheet return error when trying to use a duplicate name. Fixes #… Oct 10, 2015
sheet.go xlsxCol.CustomWidth should be boolean, not int. Feb 17, 2017
sheet_test.go xlsxCol.CustomWidth should be boolean, not int. Feb 17, 2017
style.go stylistic changes May 17, 2016
style_test.go Omit unneeded cellStyles, cellStyle, cellStyle.Xf. Mar 16, 2016
templates.go Merge output-styles branch. Dec 2, 2014
theme.go gofmt Apr 18, 2015
theme_test.go Initial support for themes Mar 15, 2015
write.go 1. make WriteSlice and WriteStruct write value with builtin format to… Aug 12, 2016
write_test.go 1. make WriteSlice and WriteStruct write value with builtin format to… Aug 12, 2016
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 Merge pull request #254 from ReneKroon/master Oct 26, 2016
xmlStyle_test.go Omit unneeded cellStyles, cellStyle, cellStyle.Xf. Mar 16, 2016
xmlTheme.go Initial support for themes Mar 15, 2015
xmlWorkbook.go added DefinedNames to the file struct by looping over defined names i… Nov 29, 2015
xmlWorkbook_test.go added DefinedNames to the file struct by looping over defined names i… Nov 29, 2015
xmlWorksheet.go xlsxCol.CustomWidth should be boolean, not int. Feb 17, 2017
xmlWorksheet_test.go Added basic support for filters. Feb 15, 2017

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!

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:

License

This code is under a BSD style license:

Copyright 2011-2015 Geoffrey Teale. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.  Redistributions
in binary form must reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.  THIS SOFTWARE IS
PROVIDED BY Geoffrey Teale ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL GEOFFREY TEALE OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Eat a peach - Geoff