Skip to content

Commit b1f632d

Browse files
committed
Resolve #393, upgrade Go module to v2
1 parent 01a418b commit b1f632d

File tree

13 files changed

+157
-148
lines changed

13 files changed

+157
-148
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Supports saving a file without losing original charts of XLSX. This library need
2121
### Installation
2222

2323
```bash
24-
go get github.com/360EntSecGroup-Skylar/excelize
24+
go get github.com/360EntSecGroup-Skylar/excelize/v2
2525
```
2626

2727
### Create XLSX file
@@ -34,7 +34,7 @@ package main
3434
import (
3535
"fmt"
3636

37-
"github.com/360EntSecGroup-Skylar/excelize"
37+
"github.com/360EntSecGroup-Skylar/excelize/v2"
3838
)
3939

4040
func main() {
@@ -64,7 +64,7 @@ package main
6464
import (
6565
"fmt"
6666

67-
"github.com/360EntSecGroup-Skylar/excelize"
67+
"github.com/360EntSecGroup-Skylar/excelize/v2"
6868
)
6969

7070
func main() {
@@ -103,7 +103,7 @@ package main
103103
import (
104104
"fmt"
105105

106-
"github.com/360EntSecGroup-Skylar/excelize"
106+
"github.com/360EntSecGroup-Skylar/excelize/v2"
107107
)
108108

109109
func main() {
@@ -140,7 +140,7 @@ import (
140140
_ "image/jpeg"
141141
_ "image/png"
142142

143-
"github.com/360EntSecGroup-Skylar/excelize"
143+
"github.com/360EntSecGroup-Skylar/excelize/v2"
144144
)
145145

146146
func main() {

README_zh.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Excelize 是 Go 语言编写的用于操作 Office Excel 文档类库,基于 E
2020
### 安装
2121

2222
```bash
23-
go get github.com/360EntSecGroup-Skylar/excelize
23+
go get github.com/360EntSecGroup-Skylar/excelize/v2
2424
```
2525

2626
### 创建 Excel 文档
@@ -33,7 +33,7 @@ package main
3333
import (
3434
"fmt"
3535

36-
"github.com/360EntSecGroup-Skylar/excelize"
36+
"github.com/360EntSecGroup-Skylar/excelize/v2"
3737
)
3838

3939
func main() {
@@ -63,7 +63,7 @@ package main
6363
import (
6464
"fmt"
6565

66-
"github.com/360EntSecGroup-Skylar/excelize"
66+
"github.com/360EntSecGroup-Skylar/excelize/v2"
6767
)
6868

6969
func main() {
@@ -102,7 +102,7 @@ package main
102102
import (
103103
"fmt"
104104

105-
"github.com/360EntSecGroup-Skylar/excelize"
105+
"github.com/360EntSecGroup-Skylar/excelize/v2"
106106
)
107107

108108
func main() {
@@ -140,7 +140,7 @@ import (
140140
_ "image/jpeg"
141141
_ "image/png"
142142

143-
"github.com/360EntSecGroup-Skylar/excelize"
143+
"github.com/360EntSecGroup-Skylar/excelize/v2"
144144
)
145145

146146
func main() {

cellmerged.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package excelize
2+
3+
import "strings"
4+
5+
// GetMergeCells provides a function to get all merged cells from a worksheet currently.
6+
func (f *File) GetMergeCells(sheet string) ([]MergeCell, error) {
7+
var mergeCells []MergeCell
8+
xlsx, err := f.workSheetReader(sheet)
9+
if err != nil {
10+
return mergeCells, err
11+
}
12+
if xlsx.MergeCells != nil {
13+
mergeCells = make([]MergeCell, 0, len(xlsx.MergeCells.Cells))
14+
15+
for i := range xlsx.MergeCells.Cells {
16+
ref := xlsx.MergeCells.Cells[i].Ref
17+
axis := strings.Split(ref, ":")[0]
18+
val, _ := f.GetCellValue(sheet, axis)
19+
mergeCells = append(mergeCells, []string{ref, val})
20+
}
21+
}
22+
23+
return mergeCells, err
24+
}
25+
26+
// MergeCell define a merged cell data.
27+
// It consists of the following structure.
28+
// example: []string{"D4:E10", "cell value"}
29+
type MergeCell []string
30+
31+
// GetCellValue returns merged cell value.
32+
func (m *MergeCell) GetCellValue() string {
33+
return (*m)[1]
34+
}
35+
36+
// GetStartAxis returns the merge start axis.
37+
// example: "C2"
38+
func (m *MergeCell) GetStartAxis() string {
39+
axis := strings.Split((*m)[0], ":")
40+
return axis[0]
41+
}
42+
43+
// GetEndAxis returns the merge end axis.
44+
// example: "D4"
45+
func (m *MergeCell) GetEndAxis() string {
46+
axis := strings.Split((*m)[0], ":")
47+
return axis[1]
48+
}

cellmerged_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package excelize
2+
3+
import (
4+
"path/filepath"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
func TestGetMergeCells(t *testing.T) {
11+
wants := []struct {
12+
value string
13+
start string
14+
end string
15+
}{{
16+
value: "A1",
17+
start: "A1",
18+
end: "B1",
19+
}, {
20+
value: "A2",
21+
start: "A2",
22+
end: "A3",
23+
}, {
24+
value: "A4",
25+
start: "A4",
26+
end: "B5",
27+
}, {
28+
value: "A7",
29+
start: "A7",
30+
end: "C10",
31+
}}
32+
33+
f, err := OpenFile(filepath.Join("test", "MergeCell.xlsx"))
34+
if !assert.NoError(t, err) {
35+
t.FailNow()
36+
}
37+
sheet1 := f.GetSheetName(1)
38+
39+
mergeCells, err := f.GetMergeCells(sheet1)
40+
if !assert.Len(t, mergeCells, len(wants)) {
41+
t.FailNow()
42+
}
43+
assert.NoError(t, err)
44+
45+
for i, m := range mergeCells {
46+
assert.Equal(t, wants[i].value, m.GetCellValue())
47+
assert.Equal(t, wants[i].start, m.GetStartAxis())
48+
assert.Equal(t, wants[i].end, m.GetEndAxis())
49+
}
50+
51+
// Test get merged cells on not exists worksheet.
52+
_, err = f.GetMergeCells("SheetN")
53+
assert.EqualError(t, err, "sheet SheetN is not exist")
54+
}

chart.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ func parseFormatChartSet(formatSet string) (*formatChart, error) {
308308
// import (
309309
// "fmt"
310310
//
311-
// "github.com/360EntSecGroup-Skylar/excelize"
311+
// "github.com/360EntSecGroup-Skylar/excelize/v2"
312312
// )
313313
//
314314
// func main() {

excelize.go

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"io/ioutil"
2020
"os"
2121
"strconv"
22-
"strings"
2322
)
2423

2524
// File define a populated XLSX file struct.
@@ -215,49 +214,3 @@ func (f *File) UpdateLinkedValue() error {
215214
}
216215
return nil
217216
}
218-
219-
// GetMergeCells provides a function to get all merged cells from a worksheet
220-
// currently.
221-
func (f *File) GetMergeCells(sheet string) ([]MergeCell, error) {
222-
var mergeCells []MergeCell
223-
xlsx, err := f.workSheetReader(sheet)
224-
if err != nil {
225-
return mergeCells, err
226-
}
227-
if xlsx.MergeCells != nil {
228-
mergeCells = make([]MergeCell, 0, len(xlsx.MergeCells.Cells))
229-
230-
for i := range xlsx.MergeCells.Cells {
231-
ref := xlsx.MergeCells.Cells[i].Ref
232-
axis := strings.Split(ref, ":")[0]
233-
val, _ := f.GetCellValue(sheet, axis)
234-
mergeCells = append(mergeCells, []string{ref, val})
235-
}
236-
}
237-
238-
return mergeCells, err
239-
}
240-
241-
// MergeCell define a merged cell data.
242-
// It consists of the following structure.
243-
// example: []string{"D4:E10", "cell value"}
244-
type MergeCell []string
245-
246-
// GetCellValue returns merged cell value.
247-
func (m *MergeCell) GetCellValue() string {
248-
return (*m)[1]
249-
}
250-
251-
// GetStartAxis returns the merge start axis.
252-
// example: "C2"
253-
func (m *MergeCell) GetStartAxis() string {
254-
axis := strings.Split((*m)[0], ":")
255-
return axis[0]
256-
}
257-
258-
// GetEndAxis returns the merge end axis.
259-
// example: "D4"
260-
func (m *MergeCell) GetEndAxis() string {
261-
axis := strings.Split((*m)[0], ":")
262-
return axis[1]
263-
}

excelize_test.go

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -407,52 +407,6 @@ func TestMergeCell(t *testing.T) {
407407
assert.NoError(t, f.SaveAs(filepath.Join("test", "TestMergeCell.xlsx")))
408408
}
409409

410-
func TestGetMergeCells(t *testing.T) {
411-
wants := []struct {
412-
value string
413-
start string
414-
end string
415-
}{{
416-
value: "A1",
417-
start: "A1",
418-
end: "B1",
419-
}, {
420-
value: "A2",
421-
start: "A2",
422-
end: "A3",
423-
}, {
424-
value: "A4",
425-
start: "A4",
426-
end: "B5",
427-
}, {
428-
value: "A7",
429-
start: "A7",
430-
end: "C10",
431-
}}
432-
433-
f, err := OpenFile(filepath.Join("test", "MergeCell.xlsx"))
434-
if !assert.NoError(t, err) {
435-
t.FailNow()
436-
}
437-
sheet1 := f.GetSheetName(1)
438-
439-
mergeCells, err := f.GetMergeCells(sheet1)
440-
if !assert.Len(t, mergeCells, len(wants)) {
441-
t.FailNow()
442-
}
443-
assert.NoError(t, err)
444-
445-
for i, m := range mergeCells {
446-
assert.Equal(t, wants[i].value, m.GetCellValue())
447-
assert.Equal(t, wants[i].start, m.GetStartAxis())
448-
assert.Equal(t, wants[i].end, m.GetEndAxis())
449-
}
450-
451-
// Test get merged cells on not exists worksheet.
452-
_, err = f.GetMergeCells("SheetN")
453-
assert.EqualError(t, err, "sheet SheetN is not exist")
454-
}
455-
456410
func TestSetCellStyleAlignment(t *testing.T) {
457411
f, err := prepareTestBook1()
458412
if !assert.NoError(t, err) {

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
module github.com/360EntSecGroup-Skylar/excelize
1+
module github.com/360EntSecGroup-Skylar/excelize/v2
2+
3+
go 1.12
24

35
require (
4-
github.com/davecgh/go-spew v1.1.1 // indirect
56
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
67
github.com/stretchr/testify v1.3.0
78
)

go.sum

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1+
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
12
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2-
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
3-
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
43
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
54
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
65
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

picture.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func parseFormatPictureSet(formatSet string) (*formatPicture, error) {
5151
// _ "image/jpeg"
5252
// _ "image/png"
5353
//
54-
// "github.com/360EntSecGroup-Skylar/excelize"
54+
// "github.com/360EntSecGroup-Skylar/excelize/v2"
5555
// )
5656
//
5757
// func main() {
@@ -111,7 +111,7 @@ func (f *File) AddPicture(sheet, cell, picture, format string) error {
111111
// _ "image/jpeg"
112112
// "io/ioutil"
113113
//
114-
// "github.com/360EntSecGroup-Skylar/excelize"
114+
// "github.com/360EntSecGroup-Skylar/excelize/v2"
115115
// )
116116
//
117117
// func main() {

0 commit comments

Comments
 (0)