Skip to content

Commit 7f3d663

Browse files
committed
This closes #1584, fix graphic object counter issues
- Optimize number format parser - Update documentation for the `AddFormControl` function - Update unit tests - Upgrade dependencies package
1 parent 8d996ca commit 7f3d663

File tree

6 files changed

+52
-52
lines changed

6 files changed

+52
-52
lines changed

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ require (
77
github.com/richardlehane/mscfb v1.0.4
88
github.com/stretchr/testify v1.8.0
99
github.com/xuri/efp v0.0.0-20230422071738-01f4e37c47e9
10-
github.com/xuri/nfp v0.0.0-20230503010013-3f38cdbb0b83
11-
golang.org/x/crypto v0.9.0
10+
github.com/xuri/nfp v0.0.0-20230723160540-a7d120392641
11+
golang.org/x/crypto v0.11.0
1212
golang.org/x/image v0.5.0
13-
golang.org/x/net v0.10.0
14-
golang.org/x/text v0.9.0
13+
golang.org/x/net v0.12.0
14+
golang.org/x/text v0.11.0
1515
)
1616

1717
require github.com/richardlehane/msoleps v1.0.3 // indirect

go.sum

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PK
1717
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
1818
github.com/xuri/efp v0.0.0-20230422071738-01f4e37c47e9 h1:ge5g8vsTQclA5lXDi+PuiAFw5GMIlMHOB/5e1hsf96E=
1919
github.com/xuri/efp v0.0.0-20230422071738-01f4e37c47e9/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI=
20-
github.com/xuri/nfp v0.0.0-20230503010013-3f38cdbb0b83 h1:xVwnvkzzi+OiwhIkWOXvh1skFI6bagk8OvGuazM80Rw=
21-
github.com/xuri/nfp v0.0.0-20230503010013-3f38cdbb0b83/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ=
20+
github.com/xuri/nfp v0.0.0-20230723160540-a7d120392641 h1:1SQuQwUorWlROdGAbsAJrMInj02yCUsYFNi/MzTJ6cA=
21+
github.com/xuri/nfp v0.0.0-20230723160540-a7d120392641/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ=
2222
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
2323
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
2424
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
25-
golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g=
26-
golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0=
25+
golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA=
26+
golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
2727
golang.org/x/image v0.5.0 h1:5JMiNunQeQw++mMOz48/ISeNu3Iweh/JaZU8ZLqHRrI=
2828
golang.org/x/image v0.5.0/go.mod h1:FVC7BI/5Ym8R25iw5OLsgshdUBbT1h5jZTpA+mvAdZ4=
2929
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
@@ -32,8 +32,9 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
3232
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
3333
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
3434
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
35-
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
3635
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
36+
golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50=
37+
golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
3738
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
3839
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
3940
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -44,16 +45,19 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc
4445
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
4546
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
4647
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
48+
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
4749
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
4850
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
4951
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
5052
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
53+
golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o=
5154
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
5255
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
5356
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
5457
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
55-
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
5658
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
59+
golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
60+
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
5761
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
5862
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
5963
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=

picture.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -308,23 +308,20 @@ func (f *File) addSheetPicture(sheet string, rID int) error {
308308
// countDrawings provides a function to get drawing files count storage in the
309309
// folder xl/drawings.
310310
func (f *File) countDrawings() int {
311-
var c1, c2 int
311+
drawings := map[string]struct{}{}
312312
f.Pkg.Range(func(k, v interface{}) bool {
313313
if strings.Contains(k.(string), "xl/drawings/drawing") {
314-
c1++
314+
drawings[k.(string)] = struct{}{}
315315
}
316316
return true
317317
})
318318
f.Drawings.Range(func(rel, value interface{}) bool {
319319
if strings.Contains(rel.(string), "xl/drawings/drawing") {
320-
c2++
320+
drawings[rel.(string)] = struct{}{}
321321
}
322322
return true
323323
})
324-
if c1 < c2 {
325-
return c2
326-
}
327-
return c1
324+
return len(drawings)
328325
}
329326

330327
// addDrawingPicture provides a function to add picture by given sheet,

pivotTable_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func TestAddPivotTable(t *testing.T) {
113113
assert.NoError(t, err)
114114
assert.NoError(t, f.AddPivotTable(&PivotTableOptions{
115115
DataRange: "Sheet1!$A$1:$E$31",
116-
PivotTableRange: "Sheet2!$A$1:$AR$15",
116+
PivotTableRange: "Sheet2!$A$1:$AN$17",
117117
Rows: []PivotTableField{{Data: "Month"}},
118118
Columns: []PivotTableField{{Data: "Region", DefaultSubtotal: true}, {Data: "Type", DefaultSubtotal: true}, {Data: "Year"}},
119119
Data: []PivotTableField{{Data: "Sales", Subtotal: "Min", Name: "Summarize by Min"}},
@@ -126,7 +126,7 @@ func TestAddPivotTable(t *testing.T) {
126126
}))
127127
assert.NoError(t, f.AddPivotTable(&PivotTableOptions{
128128
DataRange: "Sheet1!$A$1:$E$31",
129-
PivotTableRange: "Sheet2!$A$18:$AR$54",
129+
PivotTableRange: "Sheet2!$A$20:$AR$60",
130130
Rows: []PivotTableField{{Data: "Month", DefaultSubtotal: true}, {Data: "Type"}},
131131
Columns: []PivotTableField{{Data: "Region", DefaultSubtotal: true}, {Data: "Year"}},
132132
Data: []PivotTableField{{Data: "Sales", Subtotal: "Product", Name: "Summarize by Product"}},
@@ -146,7 +146,7 @@ func TestAddPivotTable(t *testing.T) {
146146
}))
147147
assert.NoError(t, f.AddPivotTable(&PivotTableOptions{
148148
DataRange: "dataRange",
149-
PivotTableRange: "Sheet2!$A$57:$AJ$91",
149+
PivotTableRange: "Sheet2!$A$65:$AJ$100",
150150
Rows: []PivotTableField{{Data: "Month", DefaultSubtotal: true}, {Data: "Year"}},
151151
Columns: []PivotTableField{{Data: "Region", DefaultSubtotal: true}, {Data: "Type"}},
152152
Data: []PivotTableField{{Data: "Sales", Subtotal: "Sum", Name: "Sum of Sales"}, {Data: "Sales", Subtotal: "Average", Name: "Average of Sales"}},

shape.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ func parseShapeOptions(opts *Shape) (*Shape, error) {
5050
}
5151

5252
// AddShape provides the method to add shape in a sheet by given worksheet
53-
// index, shape format set (such as offset, scale, aspect ratio setting and
54-
// print settings) and properties set. For example, add text box (rect shape)
55-
// in Sheet1:
53+
// name and shape format set (such as offset, scale, aspect ratio setting and
54+
// print settings). For example, add text box (rect shape) in Sheet1:
5655
//
5756
// lineWidth := 1.2
58-
// err := f.AddShape("Sheet1", "G6",
57+
// err := f.AddShape("Sheet1",
5958
// &excelize.Shape{
59+
// Cell: "G6",
6060
// Type: "rect",
6161
// Line: excelize.ShapeLine{Color: "4286F4", Width: &lineWidth},
6262
// Fill: excelize.Fill{Color: []string{"8EB9FF"}, Pattern: 1},

vml.go

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -229,22 +229,19 @@ func (f *File) addComment(commentsXML string, opts vmlOptions) error {
229229
// countComments provides a function to get comments files count storage in
230230
// the folder xl.
231231
func (f *File) countComments() int {
232-
c1, c2 := 0, 0
232+
comments := map[string]struct{}{}
233233
f.Pkg.Range(func(k, v interface{}) bool {
234234
if strings.Contains(k.(string), "xl/comments") {
235-
c1++
235+
comments[k.(string)] = struct{}{}
236236
}
237237
return true
238238
})
239239
for rel := range f.Comments {
240240
if strings.Contains(rel, "xl/comments") {
241-
c2++
241+
comments[rel] = struct{}{}
242242
}
243243
}
244-
if c1 < c2 {
245-
return c2
246-
}
247-
return c1
244+
return len(comments)
248245
}
249246

250247
// commentsReader provides a function to get the pointer to the structure
@@ -281,12 +278,12 @@ func (f *File) commentsWriter() {
281278
// XLSM or XLTM. Scroll value must be between 0 and 30000.
282279
//
283280
// Example 1, add button form control with macro, rich-text, custom button size,
284-
// print property on Sheet1!A1, and let the button do not move or size with
281+
// print property on Sheet1!A2, and let the button do not move or size with
285282
// cells:
286283
//
287284
// enable := true
288285
// err := f.AddFormControl("Sheet1", excelize.FormControl{
289-
// Cell: "A1",
286+
// Cell: "A2",
290287
// Type: excelize.FormControlButton,
291288
// Macro: "Button1_Click",
292289
// Width: 140,
@@ -321,12 +318,14 @@ func (f *File) commentsWriter() {
321318
// Checked: true,
322319
// })
323320
//
324-
// Example 3, add spin button form control on Sheet1!A2 to increase or decrease
321+
// Example 3, add spin button form control on Sheet1!B1 to increase or decrease
325322
// the value of Sheet1!A1:
326323
//
327324
// err := f.AddFormControl("Sheet1", excelize.FormControl{
328-
// Cell: "A2",
325+
// Cell: "B1",
329326
// Type: excelize.FormControlSpinButton,
327+
// Width: 15,
328+
// Height: 40,
330329
// CurrentVal: 7,
331330
// MinVal: 5,
332331
// MaxVal: 10,
@@ -338,14 +337,17 @@ func (f *File) commentsWriter() {
338337
// the value of Sheet1!A1 by click the scroll arrows or drag the scroll box:
339338
//
340339
// err := f.AddFormControl("Sheet1", excelize.FormControl{
341-
// Cell: "A2",
342-
// Type: excelize.FormControlScrollBar,
343-
// CurrentVal: 50,
344-
// MinVal: 10,
345-
// MaxVal: 100,
346-
// IncChange: 1,
347-
// PageChange: 1,
348-
// CellLink: "A1",
340+
// Cell: "A2",
341+
// Type: excelize.FormControlScrollBar,
342+
// Width: 140,
343+
// Height: 20,
344+
// CurrentVal: 50,
345+
// MinVal: 10,
346+
// MaxVal: 100,
347+
// IncChange: 1,
348+
// PageChange: 1,
349+
// CellLink: "A1",
350+
// Horizontally: true,
349351
// })
350352
func (f *File) AddFormControl(sheet string, opts FormControl) error {
351353
return f.addVMLObject(vmlOptions{
@@ -355,9 +357,9 @@ func (f *File) AddFormControl(sheet string, opts FormControl) error {
355357

356358
// DeleteFormControl provides the method to delete form control in a worksheet
357359
// by given worksheet name and cell reference. For example, delete the form
358-
// control in Sheet1!$A$30:
360+
// control in Sheet1!$A$1:
359361
//
360-
// err := f.DeleteFormControl("Sheet1", "A30")
362+
// err := f.DeleteFormControl("Sheet1", "A1")
361363
func (f *File) DeleteFormControl(sheet, cell string) error {
362364
ws, err := f.workSheetReader(sheet)
363365
if err != nil {
@@ -430,22 +432,19 @@ func (f *File) DeleteFormControl(sheet, cell string) error {
430432
// countVMLDrawing provides a function to get VML drawing files count storage
431433
// in the folder xl/drawings.
432434
func (f *File) countVMLDrawing() int {
433-
c1, c2 := 0, 0
435+
drawings := map[string]struct{}{}
434436
f.Pkg.Range(func(k, v interface{}) bool {
435437
if strings.Contains(k.(string), "xl/drawings/vmlDrawing") {
436-
c1++
438+
drawings[k.(string)] = struct{}{}
437439
}
438440
return true
439441
})
440442
for rel := range f.VMLDrawing {
441443
if strings.Contains(rel, "xl/drawings/vmlDrawing") {
442-
c2++
444+
drawings[rel] = struct{}{}
443445
}
444446
}
445-
if c1 < c2 {
446-
return c2
447-
}
448-
return c1
447+
return len(drawings)
449448
}
450449

451450
// decodeVMLDrawingReader provides a function to get the pointer to the

0 commit comments

Comments
 (0)