1 <p align="center"><img width="650" src="./excelize.svg" alt="Excelize logo"></p>
4 <a href="https://github.com/xuri/excelize/actions/workflows/go.yml"><img src="https://github.com/xuri/excelize/actions/workflows/go.yml/badge.svg" alt="Build Status"></a>
5 <a href="https://codecov.io/gh/qax-os/excelize"><img src="https://codecov.io/gh/qax-os/excelize/branch/master/graph/badge.svg" alt="Code Coverage"></a>
6 <a href="https://goreportcard.com/report/github.com/xuri/excelize/v2"><img src="https://goreportcard.com/badge/github.com/xuri/excelize/v2" alt="Go Report Card"></a>
7 <a href="https://pkg.go.dev/github.com/xuri/excelize/v2"><img src="https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white" alt="go.dev"></a>
8 <a href="https://opensource.org/licenses/BSD-3-Clause"><img src="https://img.shields.io/badge/license-bsd-orange.svg" alt="Licenses"></a>
9 <a href="https://www.paypal.com/paypalme/xuri"><img src="https://img.shields.io/badge/Donate-PayPal-green.svg" alt="Donate"></a>
16 Excelize is a library written in pure Go providing a set of functions that allow you to write to and read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports complex components by high compatibility, and provided streaming API for generating or reading data from a worksheet with huge amounts of data. This library needs Go version 1.18 or later. There are some [incompatible changes](https://github.com/golang/go/issues/61881) in the Go 1.21.0, the Excelize library can not working with that version normally, if you are using the Go 1.21.x, please upgrade to the Go 1.21.1 and later version. The full docs can be seen using go's built-in documentation tool, or online at [go.dev](https://pkg.go.dev/github.com/xuri/excelize/v2) and [docs reference](https://xuri.me/excelize/).
23 go get github.com/xuri/excelize
26 - If your packages are managed using [Go Modules](https://go.dev/blog/using-go-modules), please install with following command.
29 go get github.com/xuri/excelize/v2
32 ### Create spreadsheet
34 Here is a minimal example usage that will create spreadsheet file.
42 "github.com/xuri/excelize/v2"
46 f := excelize.NewFile()
48 if err := f.Close(); err != nil {
52 // Create a new sheet.
53 index, err := f.NewSheet("Sheet2")
58 // Set value of a cell.
59 f.SetCellValue("Sheet2", "A2", "Hello world.")
60 f.SetCellValue("Sheet1", "B2", 100)
61 // Set active sheet of the workbook.
62 f.SetActiveSheet(index)
63 // Save spreadsheet by the given path.
64 if err := f.SaveAs("Book1.xlsx"); err != nil {
70 ### Reading spreadsheet
72 The following constitutes the bare to read a spreadsheet document.
80 "github.com/xuri/excelize/v2"
84 f, err := excelize.OpenFile("Book1.xlsx")
90 // Close the spreadsheet.
91 if err := f.Close(); err != nil {
95 // Get value from cell by given worksheet name and cell reference.
96 cell, err := f.GetCellValue("Sheet1", "B2")
102 // Get all the rows in the Sheet1.
103 rows, err := f.GetRows("Sheet1")
108 for _, row := range rows {
109 for _, colCell := range row {
110 fmt.Print(colCell, "\t")
117 ### Add chart to spreadsheet file
119 With Excelize chart generation and management is as easy as a few lines of code. You can build charts based on data in your worksheet or generate charts without any data in your worksheet at all.
121 <p align="center"><img width="650" src="./test/images/chart.png" alt="Excelize"></p>
129 "github.com/xuri/excelize/v2"
133 f := excelize.NewFile()
135 if err := f.Close(); err != nil {
139 for idx, row := range [][]interface{}{
140 {nil, "Apple", "Orange", "Pear"}, {"Small", 2, 3, 3},
141 {"Normal", 5, 2, 4}, {"Large", 6, 7, 8},
143 cell, err := excelize.CoordinatesToCellName(1, idx+1)
148 f.SetSheetRow("Sheet1", cell, &row)
150 if err := f.AddChart("Sheet1", "E1", &excelize.Chart{
151 Type: excelize.Col3DClustered,
152 Series: []excelize.ChartSeries{
155 Categories: "Sheet1!$B$1:$D$1",
156 Values: "Sheet1!$B$2:$D$2",
160 Categories: "Sheet1!$B$1:$D$1",
161 Values: "Sheet1!$B$3:$D$3",
165 Categories: "Sheet1!$B$1:$D$1",
166 Values: "Sheet1!$B$4:$D$4",
168 Title: []excelize.RichTextRun{
170 Text: "Fruit 3D Clustered Column Chart",
177 // Save spreadsheet by the given path.
178 if err := f.SaveAs("Book1.xlsx"); err != nil {
184 ### Add picture to spreadsheet file
195 "github.com/xuri/excelize/v2"
199 f, err := excelize.OpenFile("Book1.xlsx")
205 // Close the spreadsheet.
206 if err := f.Close(); err != nil {
211 if err := f.AddPicture("Sheet1", "A2", "image.png", nil); err != nil {
214 // Insert a picture to worksheet with scaling.
215 if err := f.AddPicture("Sheet1", "D2", "image.jpg",
216 &excelize.GraphicOptions{ScaleX: 0.5, ScaleY: 0.5}); err != nil {
219 // Insert a picture offset in the cell with printing support.
220 enable, disable := true, false
221 if err := f.AddPicture("Sheet1", "H2", "image.gif",
222 &excelize.GraphicOptions{
223 PrintObject: &enable,
224 LockAspectRatio: false,
231 // Save the spreadsheet with the origin path.
232 if err = f.Save(); err != nil {
240 Contributions are welcome! Open a pull request to fix a bug, or open an issue to discuss a new feature or change. XML is compliant with [part 1 of the 5th edition of the ECMA-376 Standard for Office Open XML](https://www.ecma-international.org/publications-and-standards/standards/ecma-376/).
244 This program is under the terms of the BSD 3-Clause License. See [https://opensource.org/licenses/BSD-3-Clause](https://opensource.org/licenses/BSD-3-Clause).
246 The Excel logo is a trademark of [Microsoft Corporation](https://aka.ms/trademarks-usage). This artwork is an adaptation.
248 gopher.{ai,svg,png} was created by [Takuya Ueda](https://twitter.com/tenntenn). Licensed under the [Creative Commons 3.0 Attributions license](http://creativecommons.org/licenses/by/3.0/).