https://github.com/360EntSecGroup-Skylar/excelize

xuri 9c707178ff Update dependency package version and docs for the OpenFile 5 years ago
.github efe3219af0 Delete ISSUE_TEMPLATE.md 7 years ago
test 98f1a69903 support ECMA-376 document standard encryption, ref #199 5 years ago
.gitignore b1b3c0d151 Fix #539 Fixed error opening excel file created in encoding d… (#540) 6 years ago
.travis.yml c3e92a51d7 Compatible with Go 1.15, fix unit test failed on Windows and fixed #689 potential race condition 5 years ago
CODE_OF_CONDUCT.md 023dba7265 Fix #576, serialize by fields order on stream flush 5 years ago
CONTRIBUTING.md e51aff2d95 Resolve #570, flat columns for the column's operation 5 years ago
LICENSE 3f89c6e979 remove ineffectual variable assignments and simplify code 5 years ago
PULL_REQUEST_TEMPLATE.md df6b0d9ff4 Create PULL_REQUEST_TEMPLATE.md 7 years ago
README.md 49257c5918 support case-sensitive doc parts to improve compatibility 5 years ago
README_zh.md 1fe660df64 - Resolve #485 use sheet index instead of ID 5 years ago
SECURITY.md 475fbf3856 Create SECURITY.md 6 years ago
adjust.go c98fd7e5d0 Fix issue #686 RemoveRow slice bounds out of range (#687) 5 years ago
adjust_test.go 09485b3f9f Improve code coverage unit tests 6 years ago
calc.go 3cf3101fd9 test on Go 1.5 on Travis CI and update docs for the CalcCellValue 5 years ago
calc_test.go 5993a07422 Fix issue 665 (#666) 5 years ago
calcchain.go 15fd56853f Update docs and typo fixed 5 years ago
calcchain_test.go ae2865d923 Improve code coverage unit tests 6 years ago
cell.go 88de2f8d51 Default row height compatibility with Apache OpenOffice and Kingsoft WPS, unit test update and typo fixed 5 years ago
cell_test.go 88de2f8d51 Default row height compatibility with Apache OpenOffice and Kingsoft WPS, unit test update and typo fixed 5 years ago
chart.go c922c32fb7 support parse and generate XML element namespace dynamic, fix #651 5 years ago
chart_test.go 42b1c81488 Resolve #661 Add Logarithmic scale option support on Y axis (#662) 5 years ago
col.go 324f87bcae add checking and limits for the worksheet 5 years ago
col_test.go 324f87bcae add checking and limits for the worksheet 5 years ago
comment.go ee35497935 Fix #673 comment shape compatibility issue with the recent Excel versions 5 years ago
comment_test.go 3ce4b91be9 Resolve #345, fix missing comments by GetComments 5 years ago
crypt.go 01afc6e03f init ECMA-376 agile encryption support 5 years ago
crypt_test.go 01afc6e03f init ECMA-376 agile encryption support 5 years ago
datavalidation.go 15fd56853f Update docs and typo fixed 5 years ago
datavalidation_test.go 6ab5b991e4 Resolve #348, support delete Data Validation 5 years ago
date.go 15fd56853f Update docs and typo fixed 5 years ago
date_test.go 83eedce70d Export ExcelDateToTime function to convert excel date to time 5 years ago
docProps.go 15fd56853f Update docs and typo fixed 5 years ago
docProps_test.go 09485b3f9f Improve code coverage unit tests 6 years ago
drawing.go 98f1a69903 support ECMA-376 document standard encryption, ref #199 5 years ago
drawing_test.go 3ce4b91be9 Resolve #345, fix missing comments by GetComments 5 years ago
errors.go 15fd56853f Update docs and typo fixed 5 years ago
errors_test.go 83eedce70d Export ExcelDateToTime function to convert excel date to time 5 years ago
excelize.go 89465f41b5 Update dependency package version and docs for the OpenFile 5 years ago
excelize.svg 8922f65978 Combine functions: 6 years ago
excelize_test.go 98f1a69903 support ECMA-376 document standard encryption, ref #199 5 years ago
file.go 89465f41b5 Update dependency package version and docs for the OpenFile 5 years ago
file_test.go 4e4baac3bc using Mutex lock and update benchmark 5 years ago
go.mod 89465f41b5 Update dependency package version and docs for the OpenFile 5 years ago
go.sum 89465f41b5 Update dependency package version and docs for the OpenFile 5 years ago
hsl.go 3e004d900b Comments style changed. 7 years ago
lib.go c3e92a51d7 Compatible with Go 1.15, fix unit test failed on Windows and fixed #689 potential race condition 5 years ago
lib_test.go 13e7bce6d2 improvement compatibility for the XML ignorable namespace 5 years ago
logo.png beff7b4f3c Typo fixed and godoc updated 6 years ago
merge.go 88de2f8d51 Default row height compatibility with Apache OpenOffice and Kingsoft WPS, unit test update and typo fixed 5 years ago
merge_test.go 1fe660df64 - Resolve #485 use sheet index instead of ID 5 years ago
picture.go 3c8c8c55c8 resolved #691, fix the scale for add picture not work 5 years ago
picture_test.go 0aa1510694 update docs and improve compatibility 5 years ago
pivotTable.go 96917e4617 Update docs and test case for the pivot table 5 years ago
pivotTable_test.go 96917e4617 Update docs and test case for the pivot table 5 years ago
rows.go 324f87bcae add checking and limits for the worksheet 5 years ago
rows_test.go 324f87bcae add checking and limits for the worksheet 5 years ago
shape.go c922c32fb7 support parse and generate XML element namespace dynamic, fix #651 5 years ago
shape_test.go 09485b3f9f Improve code coverage unit tests 6 years ago
sheet.go 88de2f8d51 Default row height compatibility with Apache OpenOffice and Kingsoft WPS, unit test update and typo fixed 5 years ago
sheet_test.go 1fe660df64 - Resolve #485 use sheet index instead of ID 5 years ago
sheetpr.go 15fd56853f Update docs and typo fixed 5 years ago
sheetpr_test.go dfea8f96ed - New API: SetSheetFormatPr and GetSheetFormatPr 5 years ago
sheetview.go 15fd56853f Update docs and typo fixed 5 years ago
sheetview_test.go ad883caa0f Resolve #580, revert commit https://github.com/360EntSecGroup-Skylar/excelize/commit/5ca7231ed408ac264f509ff52b5d28ff4fbda757 5 years ago
sparkline.go 88de2f8d51 Default row height compatibility with Apache OpenOffice and Kingsoft WPS, unit test update and typo fixed 5 years ago
sparkline_test.go ad883caa0f Resolve #580, revert commit https://github.com/360EntSecGroup-Skylar/excelize/commit/5ca7231ed408ac264f509ff52b5d28ff4fbda757 5 years ago
stream.go bc704c854f update stream writer fields offset 5 years ago
stream_test.go c3e92a51d7 Compatible with Go 1.15, fix unit test failed on Windows and fixed #689 potential race condition 5 years ago
styles.go 324f87bcae add checking and limits for the worksheet 5 years ago
styles_test.go 324f87bcae add checking and limits for the worksheet 5 years ago
table.go ca43c65115 Update test for addTable 5 years ago
table_test.go ca43c65115 Update test for addTable 5 years ago
templates.go 15fd56853f Update docs and typo fixed 5 years ago
vmlDrawing.go 15fd56853f Update docs and typo fixed 5 years ago
xmlApp.go 15fd56853f Update docs and typo fixed 5 years ago
xmlCalcChain.go 15fd56853f Update docs and typo fixed 5 years ago
xmlChart.go 98f1a69903 support ECMA-376 document standard encryption, ref #199 5 years ago
xmlChartSheet.go 48fc4c08a2 init formula calculation engine, ref #65 and #599 5 years ago
xmlComments.go 1111de2fdb improve compatibility for phonetic hint and sheet tab color 5 years ago
xmlContentTypes.go 15fd56853f Update docs and typo fixed 5 years ago
xmlCore.go 15fd56853f Update docs and typo fixed 5 years ago
xmlDecodeDrawing.go 15fd56853f Update docs and typo fixed 5 years ago
xmlDrawing.go 324f87bcae add checking and limits for the worksheet 5 years ago
xmlPivotCache.go 97bffe608d Extend pivot table funtionality (#692) 5 years ago
xmlPivotTable.go 97bffe608d Extend pivot table funtionality (#692) 5 years ago
xmlSharedStrings.go 1111de2fdb improve compatibility for phonetic hint and sheet tab color 5 years ago
xmlStyles.go 0aa1510694 update docs and improve compatibility 5 years ago
xmlTable.go 15fd56853f Update docs and typo fixed 5 years ago
xmlTheme.go 0aa1510694 update docs and improve compatibility 5 years ago
xmlWorkbook.go 0aa1510694 update docs and improve compatibility 5 years ago
xmlWorksheet.go 1111de2fdb improve compatibility for phonetic hint and sheet tab color 5 years ago

README.md

Excelize logo

Build Status Code Coverage Go Report Card go.dev Licenses Donate

Excelize

Introduction

Excelize is a library written in pure Go providing a set of functions that allow you to write to and read from XLSX / XLSM / XLTM 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.10 or later. The full API docs can be seen using go's built-in documentation tool, or online at go.dev and docs reference.

Basic Usage

Installation

go get github.com/360EntSecGroup-Skylar/excelize
  • If your package management with Go Modules, please install with following command.
go get github.com/360EntSecGroup-Skylar/excelize/v2

Create spreadsheet

Here is a minimal example usage that will create spreadsheet file.

package main

import (
    "fmt"

    "github.com/360EntSecGroup-Skylar/excelize"
)

func main() {
    f := excelize.NewFile()
    // Create a new sheet.
    index := f.NewSheet("Sheet2")
    // Set value of a cell.
    f.SetCellValue("Sheet2", "A2", "Hello world.")
    f.SetCellValue("Sheet1", "B2", 100)
    // Set active sheet of the workbook.
    f.SetActiveSheet(index)
    // Save xlsx file by the given path.
    if err := f.SaveAs("Book1.xlsx"); err != nil {
        fmt.Println(err)
    }
}

Reading spreadsheet

The following constitutes the bare to read a spreadsheet document.

package main

import (
    "fmt"

    "github.com/360EntSecGroup-Skylar/excelize"
)

func main() {
    f, err := excelize.OpenFile("Book1.xlsx")
    if err != nil {
        fmt.Println(err)
        return
    }
    // Get value from cell by given worksheet name and axis.
    cell, err := f.GetCellValue("Sheet1", "B2")
    if err != nil {
        fmt.Println(err)
        return
    }
    fmt.Println(cell)
    // Get all the rows in the Sheet1.
    rows, err := f.GetRows("Sheet1")
    for _, row := range rows {
        for _, colCell := range row {
            fmt.Print(colCell, "\t")
        }
        fmt.Println()
    }
}

Add chart to spreadsheet file

With Excelize chart generation and management is as easy as a few lines of code. You can build charts based off data in your worksheet or generate charts without any data in your worksheet at all.

Excelize

package main

import (
    "fmt"

    "github.com/360EntSecGroup-Skylar/excelize"
)

func main() {
    categories := map[string]string{"A2": "Small", "A3": "Normal", "A4": "Large", "B1": "Apple", "C1": "Orange", "D1": "Pear"}
    values := map[string]int{"B2": 2, "C2": 3, "D2": 3, "B3": 5, "C3": 2, "D3": 4, "B4": 6, "C4": 7, "D4": 8}
    f := excelize.NewFile()
    for k, v := range categories {
        f.SetCellValue("Sheet1", k, v)
    }
    for k, v := range values {
        f.SetCellValue("Sheet1", k, v)
    }
    if err := f.AddChart("Sheet1", "E1", `{"type":"col3DClustered","series":[{"name":"Sheet1!$A$2","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$2:$D$2"},{"name":"Sheet1!$A$3","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$3:$D$3"},{"name":"Sheet1!$A$4","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$4:$D$4"}],"title":{"name":"Fruit 3D Clustered Column Chart"}}`); err != nil {
        fmt.Println(err)
        return
    }
    // Save xlsx file by the given path.
    if err := f.SaveAs("Book1.xlsx"); err != nil {
        fmt.Println(err)
    }
}

Add picture to spreadsheet file

package main

import (
    "fmt"
    _ "image/gif"
    _ "image/jpeg"
    _ "image/png"

    "github.com/360EntSecGroup-Skylar/excelize"
)

func main() {
    f, err := excelize.OpenFile("Book1.xlsx")
    if err != nil {
        fmt.Println(err)
        return
    }
    // Insert a picture.
    if err := f.AddPicture("Sheet1", "A2", "image.png", ""); err != nil {
        fmt.Println(err)
    }
    // Insert a picture to worksheet with scaling.
    if err := f.AddPicture("Sheet1", "D2", "image.jpg", `{"x_scale": 0.5, "y_scale": 0.5}`); err != nil {
        fmt.Println(err)
    }
    // Insert a picture offset in the cell with printing support.
    if err := f.AddPicture("Sheet1", "H2", "image.gif", `{"x_offset": 15, "y_offset": 10, "print_obj": true, "lock_aspect_ratio": false, "locked": false}`); err != nil {
        fmt.Println(err)
    }
    // Save the xlsx file with the origin path.
    if err = f.Save(); err != nil {
        fmt.Println(err)
    }
}

Contributing

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.

Licenses

This program is under the terms of the BSD 3-Clause License. See https://opensource.org/licenses/BSD-3-Clause.

The Excel logo is a trademark of Microsoft Corporation. This artwork is an adaptation.

gopher.{ai,svg,png} was created by Takuya Ueda. Licensed under the Creative Commons 3.0 Attributions license.