Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: qax-os/excelize
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.0.2
Choose a base ref
...
head repository: qax-os/excelize
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.1.0
Choose a head ref
Loading
Showing with 5,045 additions and 2,488 deletions.
  1. +2 −1 .gitignore
  2. +2 −1 .travis.yml
  3. +4 −2 CONTRIBUTING.md
  4. +2 −2 LICENSE
  5. +25 −47 README.md
  6. +25 −48 README_zh.md
  7. +24 −8 adjust.go
  8. +4 −0 adjust_test.go
  9. +16 −6 calcchain.go
  10. +19 −0 calcchain_test.go
  11. +102 −95 cell.go
  12. +44 −9 cell_test.go
  13. +0 −58 cellmerged.go
  14. +0 −54 cellmerged_test.go
  15. +113 −1,133 chart.go
  16. +53 −16 chart_test.go
  17. +114 −52 col.go
  18. +67 −21 col_test.go
  19. +25 −15 comment.go
  20. +56 −0 comment_test.go
  21. +1 −1 datavalidation.go
  22. +28 −29 datavalidation_test.go
  23. +1 −1 date.go
  24. +42 −26 docProps.go
  25. +16 −3 docProps_test.go
  26. +1,252 −0 drawing.go
  27. +1 −1 errors.go
  28. +81 −52 excelize.go
  29. +246 −252 excelize_test.go
  30. +3 −7 file.go
  31. +28 −0 file_test.go
  32. +2 −0 go.mod
  33. +8 −0 go.sum
  34. +15 −7 lib.go
  35. +194 −0 merge.go
  36. +169 −0 merge_test.go
  37. +96 −53 picture.go
  38. +49 −41 picture_test.go
  39. +36 −19 pivotTable.go
  40. +12 −6 pivotTable_test.go
  41. +138 −37 rows.go
  42. +148 −50 rows_test.go
  43. +5 −6 shape.go
  44. +28 −0 shape_test.go
  45. +166 −75 sheet.go
  46. +45 −8 sheet_test.go
  47. +167 −1 sheetpr.go
  48. +163 −2 sheetpr_test.go
  49. +1 −1 sheetview.go
  50. +12 −12 sheetview_test.go
  51. +78 −38 sparkline.go
  52. +41 −28 sparkline_test.go
  53. +520 −0 stream.go
  54. +167 −0 stream_test.go
  55. +38 −22 styles.go
  56. +2 −4 styles_test.go
  57. +7 −6 table.go
  58. +125 −0 table_test.go
  59. +4 −2 templates.go
  60. +1 −1 vmlDrawing.go
  61. +1 −1 xmlApp.go
  62. +1 −1 xmlCalcChain.go
  63. +25 −13 xmlChart.go
  64. +1 −1 xmlComments.go
  65. +1 −1 xmlContentTypes.go
  66. +1 −1 xmlCore.go
  67. +1 −1 xmlDecodeDrawing.go
  68. +5 −5 xmlDrawing.go
  69. +2 −2 xmlPivotCache.go
  70. +4 −4 xmlPivotTable.go
  71. +1 −1 xmlSharedStrings.go
  72. +1 −1 xmlStyles.go
  73. +2 −1 xmlTable.go
  74. +1 −1 xmlTheme.go
  75. +3 −3 xmlWorkbook.go
  76. +162 −92 xmlWorksheet.go
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
~$*.xlsx
test/Test*.xlsx
*.out
*.test
*.test
.idea
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -7,13 +7,14 @@ go:
- 1.10.x
- 1.11.x
- 1.12.x
- 1.13.x

os:
- linux
- osx

env:
matrix:
jobs:
- GOARCH=amd64
- GOARCH=386

6 changes: 4 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -234,7 +234,9 @@ By making a contribution to this project, I certify that:

Then you just add a line to every git commit message:

Signed-off-by: Ri Xu https://xuri.me
```text
Signed-off-by: Ri Xu https://xuri.me
```

Use your real name (sorry, no pseudonyms or anonymous contributions.)

@@ -460,4 +462,4 @@ Do not use package math/rand to generate keys, even
throwaway ones. Unseeded, the generator is completely predictable.
Seeded with time.Nanoseconds(), there are just a few bits of entropy.
Instead, use crypto/rand's Reader, and if you need text, print to
hexadecimal or base64
hexadecimal or base64.
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
BSD 3-Clause License

Copyright (c) 2016-2019, 360 Enterprise Security Group, Endpoint Security, Inc.
Copyright (c) 2011-2017, Geoffrey J. Teale (complying with the tealeg/xlsx license)
Copyright (c) 2016-2020, 360 Enterprise Security Group, Endpoint Security, Inc.
Copyright (c) 2011-2017, Geoffrey J. Teale
All rights reserved.

Redistribution and use in source and binary forms, with or without
72 changes: 25 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
@@ -31,11 +31,7 @@ Here is a minimal example usage that will create XLSX file.
```go
package main

import (
"fmt"

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

func main() {
f := excelize.NewFile()
@@ -47,9 +43,8 @@ func main() {
// Set active sheet of the workbook.
f.SetActiveSheet(index)
// Save xlsx file by the given path.
err := f.SaveAs("./Book1.xlsx")
if err != nil {
fmt.Println(err)
if err := f.SaveAs("Book1.xlsx"); err != nil {
println(err.Error())
}
}
```
@@ -61,32 +56,28 @@ The following constitutes the bare to read a XLSX document.
```go
package main

import (
"fmt"

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

func main() {
f, err := excelize.OpenFile("./Book1.xlsx")
f, err := excelize.OpenFile("Book1.xlsx")
if err != nil {
fmt.Println(err)
println(err.Error())
return
}
// Get value from cell by given worksheet name and axis.
cell, err := f.GetCellValue("Sheet1", "B2")
if err != nil {
fmt.Println(err)
println(err.Error())
return
}
fmt.Println(cell)
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")
print(colCell, "\t")
}
fmt.Println()
println()
}
}
```
@@ -100,11 +91,7 @@ With Excelize chart generation and management is as easy as a few lines of code.
```go
package main

import (
"fmt"

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

func main() {
categories := map[string]string{"A2": "Small", "A3": "Normal", "A4": "Large", "B1": "Apple", "C1": "Orange", "D1": "Pear"}
@@ -116,15 +103,13 @@ func main() {
for k, v := range values {
f.SetCellValue("Sheet1", k, v)
}
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"}}`)
if err != nil {
fmt.Println(err)
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 {
println(err.Error())
return
}
// Save xlsx file by the given path.
err = f.SaveAs("./Book1.xlsx")
if err != nil {
fmt.Println(err)
if err := f.SaveAs("Book1.xlsx"); err != nil {
println(err.Error())
}
}
```
@@ -135,7 +120,6 @@ func main() {
package main

import (
"fmt"
_ "image/gif"
_ "image/jpeg"
_ "image/png"
@@ -144,30 +128,26 @@ import (
)

func main() {
f, err := excelize.OpenFile("./Book1.xlsx")
f, err := excelize.OpenFile("Book1.xlsx")
if err != nil {
fmt.Println(err)
println(err.Error())
return
}
// Insert a picture.
err = f.AddPicture("Sheet1", "A2", "./image1.png", "")
if err != nil {
fmt.Println(err)
if err := f.AddPicture("Sheet1", "A2", "image.png", ""); err != nil {
println(err.Error())
}
// Insert a picture to worksheet with scaling.
err = f.AddPicture("Sheet1", "D2", "./image2.jpg", `{"x_scale": 0.5, "y_scale": 0.5}`)
if err != nil {
fmt.Println(err)
if err := f.AddPicture("Sheet1", "D2", "image.jpg", `{"x_scale": 0.5, "y_scale": 0.5}`); err != nil {
println(err.Error())
}
// Insert a picture offset in the cell with printing support.
err = f.AddPicture("Sheet1", "H2", "./image3.gif", `{"x_offset": 15, "y_offset": 10, "print_obj": true, "lock_aspect_ratio": false, "locked": false}`)
if err != nil {
fmt.Println(err)
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 {
println(err.Error())
}
// Save the xlsx file with the origin path.
err = f.Save()
if err != nil {
fmt.Println(err)
if err = f.Save(); err != nil {
println(err.Error())
}
}
```
@@ -182,6 +162,4 @@ This program is under the terms of the BSD 3-Clause License. See [https://openso

The Excel logo is a trademark of [Microsoft Corporation](https://aka.ms/trademarks-usage). This artwork is an adaptation.

Some struct of XML originally by [tealeg/xlsx](https://github.com/tealeg/xlsx). Licensed under the [BSD 3-Clause License](https://github.com/tealeg/xlsx/blob/master/LICENSE).

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/).
73 changes: 25 additions & 48 deletions README_zh.md
Original file line number Diff line number Diff line change
@@ -30,11 +30,7 @@ go get github.com/360EntSecGroup-Skylar/excelize
```go
package main

import (
"fmt"

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

func main() {
f := excelize.NewFile()
@@ -46,9 +42,8 @@ func main() {
// 设置工作簿的默认工作表
f.SetActiveSheet(index)
// 根据指定路径保存文件
err := f.SaveAs("./Book1.xlsx")
if err != nil {
fmt.Println(err)
if err := f.SaveAs("Book1.xlsx"); err != nil {
println(err.Error())
}
}
```
@@ -60,32 +55,28 @@ func main() {
```go
package main

import (
"fmt"

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

func main() {
f, err := excelize.OpenFile("./Book1.xlsx")
f, err := excelize.OpenFile("Book1.xlsx")
if err != nil {
fmt.Println(err)
println(err.Error())
return
}
// 获取工作表中指定单元格的值
cell, err := f.GetCellValue("Sheet1", "B2")
if err != nil {
fmt.Println(err)
println(err.Error())
return
}
fmt.Println(cell)
println(cell)
// 获取 Sheet1 上所有单元格
rows, err := f.GetRows("Sheet1")
for _, row := range rows {
for _, colCell := range row {
fmt.Print(colCell, "\t")
print(colCell, "\t")
}
fmt.Println()
println()
}
}
```
@@ -99,11 +90,7 @@ func main() {
```go
package main

import (
"fmt"

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

func main() {
categories := map[string]string{"A2": "Small", "A3": "Normal", "A4": "Large", "B1": "Apple", "C1": "Orange", "D1": "Pear"}
@@ -115,18 +102,15 @@ func main() {
for k, v := range values {
f.SetCellValue("Sheet1", k, v)
}
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"}}`)
if err != nil {
fmt.Println(err)
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 {
println(err.Error())
return
}
// 根据指定路径保存文件
err = f.SaveAs("./Book1.xlsx")
if err != nil {
fmt.Println(err)
if err := f.SaveAs("Book1.xlsx"); err != nil {
println(err.Error())
}
}

```

### 向 Excel 文档中插入图片
@@ -135,7 +119,6 @@ func main() {
package main

import (
"fmt"
_ "image/gif"
_ "image/jpeg"
_ "image/png"
@@ -144,30 +127,26 @@ import (
)

func main() {
f, err := excelize.OpenFile("./Book1.xlsx")
f, err := excelize.OpenFile("Book1.xlsx")
if err != nil {
fmt.Println(err)
println(err.Error())
return
}
// 插入图片
err = f.AddPicture("Sheet1", "A2", "./image1.png", "")
if err != nil {
fmt.Println(err)
if err := f.AddPicture("Sheet1", "A2", "image.png", ""); err != nil {
println(err.Error())
}
// 在工作表中插入图片,并设置图片的缩放比例
err = f.AddPicture("Sheet1", "D2", "./image2.jpg", `{"x_scale": 0.5, "y_scale": 0.5}`)
if err != nil {
fmt.Println(err)
if err := f.AddPicture("Sheet1", "D2", "image.jpg", `{"x_scale": 0.5, "y_scale": 0.5}`); err != nil {
println(err.Error())
}
// 在工作表中插入图片,并设置图片的打印属性
err = f.AddPicture("Sheet1", "H2", "./image3.gif", `{"x_offset": 15, "y_offset": 10, "print_obj": true, "lock_aspect_ratio": false, "locked": false}`)
if err != nil {
fmt.Println(err)
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 {
println(err.Error())
}
// 保存文件
err = f.Save()
if err != nil {
fmt.Println(err)
if err = f.Save(); err != nil {
println(err.Error())
}
}
```
@@ -182,6 +161,4 @@ func main() {

Excel 徽标是 [Microsoft Corporation](https://aka.ms/trademarks-usage) 的商标,项目的图片是一种改编。

本类库中部分 XML 结构体的定义参考了开源项目:[tealeg/xlsx](https://github.com/tealeg/xlsx),遵循 [BSD 3-Clause License](https://github.com/tealeg/xlsx/blob/master/LICENSE) 开源许可协议。

gopher.{ai,svg,png} 由 [Takuya Ueda](https://twitter.com/tenntenn) 创作,遵循 [Creative Commons 3.0 Attributions license](http://creativecommons.org/licenses/by/3.0/) 创作共用授权条款。
Loading