$git clone https://github.com/qax-os/excelizeExcelize 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 component
| 1 | <p align="center"><img width="650" src="./excelize.svg" alt="Excelize logo"></p> |
| 2 | |
| 3 | <p align="center"> |
| 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://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> |
| 7 | <a href="https://opensource.org/licenses/BSD-3-Clause"><img src="https://img.shields.io/badge/license-bsd-orange.svg" alt="Licenses"></a> |
| 8 | <a href="https://www.paypal.com/paypalme/xuri"><img src="https://img.shields.io/badge/Donate-PayPal-green.svg" alt="Donate"></a> |
| 9 | </p> |
| 10 | |
| 11 | # Excelize |
| 12 | |
| 13 | ## Introduction |
| 14 | |
| 15 | 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.25.0 or later. 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/). |
| 16 | |
| 17 | ## Basic Usage |
| 18 | |
| 19 | ### Installation |
| 20 | |
| 21 | ```bash |
| 22 | go get github.com/xuri/excelize |
| 23 | ``` |
| 24 | |
| 25 | - If your packages are managed using [Go Modules](https://go.dev/blog/using-go-modules), please install with following command. |
| 26 | |
| 27 | ```bash |
| 28 | go get github.com/xuri/excelize/v2 |
| 29 | ``` |
| 30 | |
| 31 | ### Create spreadsheet |
| 32 | |
| 33 | Here is a minimal example usage that will create spreadsheet file. |
| 34 | |
| 35 | ```go |
| 36 | package main |
| 37 | |
| 38 | import ( |
| 39 | "fmt" |
| 40 | |
| 41 | "github.com/xuri/excelize/v2" |
| 42 | ) |
| 43 | |
| 44 | func main() { |
| 45 | f := excelize.NewFile() |
| 46 | defer func() { |
| 47 | if err := f.Close(); err != nil { |
| 48 | fmt.Println(err) |
| 49 | } |
| 50 | }() |
| 51 | // Create a new sheet. |
| 52 | index, err := f.NewSheet("Sheet2") |
| 53 | if err != nil { |
| 54 | fmt.Println(err) |
| 55 | return |
| 56 | } |
| 57 | // Set value of a cell. |
| 58 | f.SetCellValue("Sheet2", "A2", "Hello world.") |
| 59 | f.SetCellValue("Sheet1", "B2", 100) |
| 60 | // Set active sheet of the workbook. |
| 61 | f.SetActiveSheet(index) |
| 62 | // Save spreadsheet by the given path. |
| 63 | if err := f.SaveAs("Book1.xlsx"); err != nil { |
| 64 | fmt.Println(err) |
| 65 | } |
| 66 | } |
| 67 | ``` |
| 68 | |
| 69 | ### Reading spreadsheet |
| 70 | |
| 71 | The following constitutes the bare to read a spreadsheet document. |
| 72 | |
| 73 | ```go |
| 74 | package main |
| 75 | |
| 76 | import ( |
| 77 | "fmt" |
| 78 | |
| 79 | "github.com/xuri/excelize/v2" |
| 80 | ) |
| 81 | |
| 82 | func main() { |
| 83 | f, err := excelize.OpenFile("Book1.xlsx") |
| 84 | if err != nil { |
| 85 | fmt.Println(err) |
| 86 | return |
| 87 | } |
| 88 | defer func() { |
| 89 | // Close the spreadsheet. |
| 90 | if err := f.Close(); err != nil { |
| 91 | fmt.Println(err) |
| 92 | } |
| 93 | }() |
| 94 | // Get value from cell by given worksheet name and cell reference. |
| 95 | cell, err := f.GetCellValue("Sheet1", "B2") |
| 96 | if err != nil { |
| 97 | fmt.Println(err) |
| 98 | return |
| 99 | } |
| 100 | fmt.Println(cell) |
| 101 | // Get all the rows in the Sheet1. |
| 102 | rows, err := f.GetRows("Sheet1") |
| 103 | if err != nil { |
| 104 | fmt.Println(err) |
| 105 | return |
| 106 | } |
| 107 | for _, row := range rows { |
| 108 | for _, colCell := range row { |
| 109 | fmt.Print(colCell, "\t") |
| 110 | } |
| 111 | fmt.Println() |
| 112 | } |
| 113 | } |
| 114 | ``` |
| 115 | |
| 116 | ### Add chart to spreadsheet file |
| 117 | |
| 118 | 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. |
| 119 | |
| 120 | <p align="center"><img width="650" src="./test/images/chart.png" alt="Excelize"></p> |
| 121 | |
| 122 | ```go |
| 123 | package main |
| 124 | |
| 125 | import ( |
| 126 | "fmt" |
| 127 | |
| 128 | "github.com/xuri/excelize/v2" |
| 129 | ) |
| 130 | |
| 131 | func main() { |
| 132 | f := excelize.NewFile() |
| 133 | defer func() { |
| 134 | if err := f.Close(); e |