Skip to content

Commit 6d7c45f

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents eea1d9a + 9fe3a92 commit 6d7c45f

File tree

10 files changed

+4271
-4261
lines changed

10 files changed

+4271
-4261
lines changed

calc_test.go

Lines changed: 4220 additions & 4220 deletions
Large diffs are not rendered by default.

calcchain_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func TestDeleteCalcChain(t *testing.T) {
3232
assert.EqualError(t, f.SetCellFormula("Sheet1", "A1", ""), "XML syntax error on line 1: invalid UTF-8")
3333

3434
formulaType, ref := STCellFormulaTypeShared, "C1:C5"
35-
assert.NoError(t, f.SetCellFormula("Sheet1", "C1", "=A1+B1", FormulaOpts{Ref: &ref, Type: &formulaType}))
35+
assert.NoError(t, f.SetCellFormula("Sheet1", "C1", "A1+B1", FormulaOpts{Ref: &ref, Type: &formulaType}))
3636

3737
// Test delete calculation chain with unsupported charset calculation chain
3838
f.CalcChain = nil

cell.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -712,41 +712,41 @@ type FormulaOpts struct {
712712
// calculate the formula automatically when the workbook has been opened,
713713
// please call "UpdateLinkedValue" after setting the cell formula functions.
714714
//
715-
// Example 1, set normal formula "=SUM(A1,B1)" for the cell "A3" on "Sheet1":
715+
// Example 1, set normal formula "SUM(A1,B1)" for the cell "A3" on "Sheet1":
716716
//
717-
// err := f.SetCellFormula("Sheet1", "A3", "=SUM(A1,B1)")
717+
// err := f.SetCellFormula("Sheet1", "A3", "SUM(A1,B1)")
718718
//
719719
// Example 2, set one-dimensional vertical constant array (column array) formula
720720
// "1,2,3" for the cell "A3" on "Sheet1":
721721
//
722-
// err := f.SetCellFormula("Sheet1", "A3", "={1;2;3}")
722+
// err := f.SetCellFormula("Sheet1", "A3", "{1;2;3}")
723723
//
724724
// Example 3, set one-dimensional horizontal constant array (row array)
725725
// formula '"a","b","c"' for the cell "A3" on "Sheet1":
726726
//
727-
// err := f.SetCellFormula("Sheet1", "A3", "={\"a\",\"b\",\"c\"}")
727+
// err := f.SetCellFormula("Sheet1", "A3", "{\"a\",\"b\",\"c\"}")
728728
//
729729
// Example 4, set two-dimensional constant array formula '{1,2,"a","b"}' for
730730
// the cell "A3" on "Sheet1":
731731
//
732732
// formulaType, ref := excelize.STCellFormulaTypeArray, "A3:A3"
733-
// err := f.SetCellFormula("Sheet1", "A3", "={1,2;\"a\",\"b\"}",
733+
// err := f.SetCellFormula("Sheet1", "A3", "{1,2;\"a\",\"b\"}",
734734
// excelize.FormulaOpts{Ref: &ref, Type: &formulaType})
735735
//
736736
// Example 5, set range array formula "A1:A2" for the cell "A3" on "Sheet1":
737737
//
738738
// formulaType, ref := excelize.STCellFormulaTypeArray, "A3:A3"
739-
// err := f.SetCellFormula("Sheet1", "A3", "=A1:A2",
739+
// err := f.SetCellFormula("Sheet1", "A3", "A1:A2",
740740
// excelize.FormulaOpts{Ref: &ref, Type: &formulaType})
741741
//
742-
// Example 6, set shared formula "=A1+B1" for the cell "C1:C5"
742+
// Example 6, set shared formula "A1+B1" for the cell "C1:C5"
743743
// on "Sheet1", "C1" is the master cell:
744744
//
745745
// formulaType, ref := excelize.STCellFormulaTypeShared, "C1:C5"
746-
// err := f.SetCellFormula("Sheet1", "C1", "=A1+B1",
746+
// err := f.SetCellFormula("Sheet1", "C1", "A1+B1",
747747
// excelize.FormulaOpts{Ref: &ref, Type: &formulaType})
748748
//
749-
// Example 7, set table formula "=SUM(Table1[[A]:[B]])" for the cell "C2"
749+
// Example 7, set table formula "SUM(Table1[[A]:[B]])" for the cell "C2"
750750
// on "Sheet1":
751751
//
752752
// package main
@@ -777,7 +777,7 @@ type FormulaOpts struct {
777777
// return
778778
// }
779779
// formulaType := excelize.STCellFormulaTypeDataTable
780-
// if err := f.SetCellFormula("Sheet1", "C2", "=SUM(Table1[[A]:[B]])",
780+
// if err := f.SetCellFormula("Sheet1", "C2", "SUM(Table1[[A]:[B]])",
781781
// excelize.FormulaOpts{Type: &formulaType}); err != nil {
782782
// fmt.Println(err)
783783
// return

cell_test.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ func TestGetCellFormula(t *testing.T) {
637637
// formula cell reference range covered the previous.
638638
f = NewFile()
639639
formulaType, ref = STCellFormulaTypeShared, "C2:C6"
640-
assert.NoError(t, f.SetCellFormula("Sheet1", "C2", "=A2+B2", FormulaOpts{Ref: &ref, Type: &formulaType}))
640+
assert.NoError(t, f.SetCellFormula("Sheet1", "C2", "A2+B2", FormulaOpts{Ref: &ref, Type: &formulaType}))
641641
formula, err = f.GetCellFormula("Sheet1", "C2")
642642
assert.NoError(t, err)
643643
assert.Equal(t, "A2+B2", formula)
@@ -646,7 +646,7 @@ func TestGetCellFormula(t *testing.T) {
646646
assert.Equal(t, "A6+B6", formula)
647647

648648
formulaType, ref = STCellFormulaTypeShared, "C2:C8"
649-
assert.NoError(t, f.SetCellFormula("Sheet1", "C2", "=A2*B2", FormulaOpts{Ref: &ref, Type: &formulaType}))
649+
assert.NoError(t, f.SetCellFormula("Sheet1", "C2", "A2*B2", FormulaOpts{Ref: &ref, Type: &formulaType}))
650650
formula, err = f.GetCellFormula("Sheet1", "C2")
651651
assert.NoError(t, err)
652652
assert.Equal(t, "A2*B2", formula)
@@ -659,7 +659,7 @@ func TestGetCellFormula(t *testing.T) {
659659
// formula cell reference range not over the previous.
660660
f = NewFile()
661661
formulaType, ref = STCellFormulaTypeShared, "C2:C6"
662-
assert.NoError(t, f.SetCellFormula("Sheet1", "C2", "=A2+B2", FormulaOpts{Ref: &ref, Type: &formulaType}))
662+
assert.NoError(t, f.SetCellFormula("Sheet1", "C2", "A2+B2", FormulaOpts{Ref: &ref, Type: &formulaType}))
663663
formula, err = f.GetCellFormula("Sheet1", "C2")
664664
assert.NoError(t, err)
665665
assert.Equal(t, "A2+B2", formula)
@@ -668,7 +668,7 @@ func TestGetCellFormula(t *testing.T) {
668668
assert.Equal(t, "A6+B6", formula)
669669

670670
formulaType, ref = STCellFormulaTypeShared, "C2:C4"
671-
assert.NoError(t, f.SetCellFormula("Sheet1", "C2", "=A2*B2", FormulaOpts{Ref: &ref, Type: &formulaType}))
671+
assert.NoError(t, f.SetCellFormula("Sheet1", "C2", "A2*B2", FormulaOpts{Ref: &ref, Type: &formulaType}))
672672
formula, err = f.GetCellFormula("Sheet1", "C2")
673673
assert.NoError(t, err)
674674
assert.Equal(t, "A2*B2", formula)
@@ -679,7 +679,7 @@ func TestGetCellFormula(t *testing.T) {
679679
// Test get shared formula after remove refer cell formula
680680
f = NewFile()
681681
formulaType, ref = STCellFormulaTypeShared, "C2:C6"
682-
assert.NoError(t, f.SetCellFormula("Sheet1", "C2", "=A2+B2", FormulaOpts{Ref: &ref, Type: &formulaType}))
682+
assert.NoError(t, f.SetCellFormula("Sheet1", "C2", "A2+B2", FormulaOpts{Ref: &ref, Type: &formulaType}))
683683

684684
assert.NoError(t, f.SetCellFormula("Sheet1", "C2", ""))
685685

@@ -691,7 +691,7 @@ func TestGetCellFormula(t *testing.T) {
691691
assert.Empty(t, formula)
692692

693693
formulaType, ref = STCellFormulaTypeShared, "C2:C8"
694-
assert.NoError(t, f.SetCellFormula("Sheet1", "C2", "=A2*B2", FormulaOpts{Ref: &ref, Type: &formulaType}))
694+
assert.NoError(t, f.SetCellFormula("Sheet1", "C2", "A2*B2", FormulaOpts{Ref: &ref, Type: &formulaType}))
695695
formula, err = f.GetCellFormula("Sheet1", "C2")
696696
assert.NoError(t, err)
697697
assert.Equal(t, "A2*B2", formula)
@@ -791,16 +791,16 @@ func TestSetCellFormula(t *testing.T) {
791791
assert.NoError(t, f.SetSheetRow("Sheet1", fmt.Sprintf("A%d", r), &[]interface{}{r, r + 1}))
792792
}
793793
formulaType, ref := STCellFormulaTypeShared, "C1:C5"
794-
assert.NoError(t, f.SetCellFormula("Sheet1", "C1", "=A1+B1", FormulaOpts{Ref: &ref, Type: &formulaType}))
794+
assert.NoError(t, f.SetCellFormula("Sheet1", "C1", "A1+B1", FormulaOpts{Ref: &ref, Type: &formulaType}))
795795
sharedFormulaSpreadsheet := filepath.Join("test", "TestSetCellFormula4.xlsx")
796796
assert.NoError(t, f.SaveAs(sharedFormulaSpreadsheet))
797797

798798
f, err = OpenFile(sharedFormulaSpreadsheet)
799799
assert.NoError(t, err)
800800
ref = "D1:D5"
801-
assert.NoError(t, f.SetCellFormula("Sheet1", "D1", "=A1+C1", FormulaOpts{Ref: &ref, Type: &formulaType}))
801+
assert.NoError(t, f.SetCellFormula("Sheet1", "D1", "A1+C1", FormulaOpts{Ref: &ref, Type: &formulaType}))
802802
ref = ""
803-
assert.Equal(t, ErrParameterInvalid, f.SetCellFormula("Sheet1", "D1", "=A1+C1", FormulaOpts{Ref: &ref, Type: &formulaType}))
803+
assert.Equal(t, ErrParameterInvalid, f.SetCellFormula("Sheet1", "D1", "A1+C1", FormulaOpts{Ref: &ref, Type: &formulaType}))
804804
assert.NoError(t, f.SaveAs(filepath.Join("test", "TestSetCellFormula5.xlsx")))
805805

806806
// Test set table formula for the cells
@@ -810,7 +810,7 @@ func TestSetCellFormula(t *testing.T) {
810810
}
811811
assert.NoError(t, f.AddTable("Sheet1", &Table{Range: "A1:C2", Name: "Table1", StyleName: "TableStyleMedium2"}))
812812
formulaType = STCellFormulaTypeDataTable
813-
assert.NoError(t, f.SetCellFormula("Sheet1", "C2", "=SUM(Table1[[A]:[B]])", FormulaOpts{Type: &formulaType}))
813+
assert.NoError(t, f.SetCellFormula("Sheet1", "C2", "SUM(Table1[[A]:[B]])", FormulaOpts{Type: &formulaType}))
814814
assert.NoError(t, f.SaveAs(filepath.Join("test", "TestSetCellFormula6.xlsx")))
815815

816816
// Test set array formula with invalid cell range reference
@@ -1178,6 +1178,9 @@ func TestSharedStringsError(t *testing.T) {
11781178
assert.True(t, ok)
11791179
f.tempFiles.Store(defaultXMLPathSharedStrings, "")
11801180
assert.Equal(t, "1", f.getFromStringItem(1))
1181+
// Test get from string item with invalid offset range
1182+
f.sharedStringItem = [][]uint{{0}}
1183+
assert.Equal(t, "0", f.getFromStringItem(0))
11811184
// Cleanup undelete temporary files
11821185
assert.NoError(t, os.Remove(tempFile.(string)))
11831186
// Test reload the file error on set cell value and rich text. The error message was different between macOS and Windows

go.mod

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ go 1.23.0
55
require (
66
github.com/richardlehane/mscfb v1.0.4
77
github.com/stretchr/testify v1.10.0
8-
github.com/tiendc/go-deepcopy v1.6.0
8+
github.com/tiendc/go-deepcopy v1.6.1
99
github.com/xuri/efp v0.0.1
10-
github.com/xuri/nfp v0.0.1
11-
golang.org/x/crypto v0.38.0
10+
github.com/xuri/nfp v0.0.2-0.20250530014748-2ddeb826f9a9
11+
golang.org/x/crypto v0.39.0
1212
golang.org/x/image v0.25.0
13-
golang.org/x/net v0.40.0
14-
golang.org/x/text v0.25.0
13+
golang.org/x/net v0.41.0
14+
golang.org/x/text v0.26.0
1515
)
1616

1717
require (

go.sum

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ github.com/richardlehane/msoleps v1.0.4 h1:WuESlvhX3gH2IHcd8UqyCuFY5yiq/GR/yqaSM
99
github.com/richardlehane/msoleps v1.0.4/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg=
1010
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
1111
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
12-
github.com/tiendc/go-deepcopy v1.6.0 h1:0UtfV/imoCwlLxVsyfUd4hNHnB3drXsfle+wzSCA5Wo=
13-
github.com/tiendc/go-deepcopy v1.6.0/go.mod h1:toXoeQoUqXOOS/X4sKuiAoSk6elIdqc0pN7MTgOOo2I=
12+
github.com/tiendc/go-deepcopy v1.6.1 h1:uVRTItFeNHkMcLueHS7OCsxgxT9P8MzGB/taUa2Y4Tk=
13+
github.com/tiendc/go-deepcopy v1.6.1/go.mod h1:toXoeQoUqXOOS/X4sKuiAoSk6elIdqc0pN7MTgOOo2I=
1414
github.com/xuri/efp v0.0.1 h1:fws5Rv3myXyYni8uwj2qKjVaRP30PdjeYe2Y6FDsCL8=
1515
github.com/xuri/efp v0.0.1/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI=
16-
github.com/xuri/nfp v0.0.1 h1:MDamSGatIvp8uOmDP8FnmjuQpu90NzdJxo7242ANR9Q=
17-
github.com/xuri/nfp v0.0.1/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ=
18-
golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8=
19-
golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw=
16+
github.com/xuri/nfp v0.0.2-0.20250530014748-2ddeb826f9a9 h1:+C0TIdyyYmzadGaL/HBLbf3WdLgC29pgyhTjAT/0nuE=
17+
github.com/xuri/nfp v0.0.2-0.20250530014748-2ddeb826f9a9/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ=
18+
golang.org/x/crypto v0.39.0 h1:SHs+kF4LP+f+p14esP5jAoDpHU8Gu/v9lFRK6IT5imM=
19+
golang.org/x/crypto v0.39.0/go.mod h1:L+Xg3Wf6HoL4Bn4238Z6ft6KfEpN0tJGo53AAPC632U=
2020
golang.org/x/image v0.25.0 h1:Y6uW6rH1y5y/LK1J8BPWZtr6yZ7hrsy6hFrXjgsc2fQ=
2121
golang.org/x/image v0.25.0/go.mod h1:tCAmOEGthTtkalusGp1g3xa2gke8J6c2N565dTyl9Rs=
22-
golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY=
23-
golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds=
24-
golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4=
25-
golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA=
22+
golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw=
23+
golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA=
24+
golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=
25+
golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=
2626
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
2727
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
2828
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

numfmt_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ func TestNumFmt(t *testing.T) {
1111
for _, item := range [][]string{
1212
{"123", "general", "123"},
1313
{"-123", ";general", "-123"},
14+
{"123.456", "0.00\"\"", "123.46"},
15+
{"123.456", "\"\";\"\"", ""},
16+
{"123.456", "\"\"0.00foo", "123.46foo"},
17+
{"123.456", "\"\"0.00\"foo\"", "123.46foo"},
1418
{"12345678901", "General", "12345678901"},
1519
{"43543.5448726851", "General", "43543.54487"},
1620
{"-43543.5448726851", "General", "-43543.54487"},

picture_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ func TestGetPicture(t *testing.T) {
268268
// Test get embedded cell pictures
269269
f, err = OpenFile(filepath.Join("test", "TestGetPicture.xlsx"))
270270
assert.NoError(t, err)
271-
assert.NoError(t, f.SetCellFormula("Sheet1", "F21", "=_xlfn.DISPIMG(\"ID_********************************\",1)"))
271+
assert.NoError(t, f.SetCellFormula("Sheet1", "F21", "_xlfn.DISPIMG(\"ID_********************************\",1)"))
272272
f.Pkg.Store(defaultXMLPathCellImages, []byte(`<etc:cellImages xmlns:etc="http://www.wps.cn/officeDocument/2017/etCustomData"><etc:cellImage><xdr:pic><xdr:nvPicPr><xdr:cNvPr id="1" name="ID_********************************" descr="CellImage1"/></xdr:nvPicPr><xdr:blipFill><a:blip r:embed="rId1"/></xdr:blipFill></xdr:pic></etc:cellImage></etc:cellImages>`))
273273
f.Pkg.Store(defaultXMLPathCellImagesRels, []byte(fmt.Sprintf(`<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="%s" Target="media/image1.jpeg"/></Relationships>`, SourceRelationshipImage)))
274274
pics, err = f.GetPictures("Sheet1", "F21")
@@ -278,7 +278,7 @@ func TestGetPicture(t *testing.T) {
278278
assert.Equal(t, PictureInsertTypeDISPIMG, pics[0].InsertType)
279279

280280
// Test get embedded cell pictures with invalid formula
281-
assert.NoError(t, f.SetCellFormula("Sheet1", "A1", "=_xlfn.DISPIMG()"))
281+
assert.NoError(t, f.SetCellFormula("Sheet1", "A1", "_xlfn.DISPIMG()"))
282282
_, err = f.GetPictures("Sheet1", "A1")
283283
assert.EqualError(t, err, "DISPIMG requires 2 numeric arguments")
284284

@@ -458,13 +458,13 @@ func TestGetPictureCells(t *testing.T) {
458458
// Test get embedded picture cells
459459
f = NewFile()
460460
assert.NoError(t, f.AddPicture("Sheet1", "A1", filepath.Join("test", "images", "excel.png"), nil))
461-
assert.NoError(t, f.SetCellFormula("Sheet1", "A2", "=_xlfn.DISPIMG(\"ID_********************************\",1)"))
461+
assert.NoError(t, f.SetCellFormula("Sheet1", "A2", "_xlfn.DISPIMG(\"ID_********************************\",1)"))
462462
cells, err = f.GetPictureCells("Sheet1")
463463
assert.NoError(t, err)
464464
assert.Equal(t, []string{"A2", "A1"}, cells)
465465

466466
// Test get embedded cell pictures with invalid formula
467-
assert.NoError(t, f.SetCellFormula("Sheet1", "A2", "=_xlfn.DISPIMG()"))
467+
assert.NoError(t, f.SetCellFormula("Sheet1", "A2", "_xlfn.DISPIMG()"))
468468
_, err = f.GetPictureCells("Sheet1")
469469
assert.EqualError(t, err, "DISPIMG requires 2 numeric arguments")
470470
assert.NoError(t, f.Close())

rows.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,9 @@ func (f *File) getFromStringItem(index int) string {
355355
return strconv.Itoa(index)
356356
}
357357
offsetRange := f.sharedStringItem[index]
358+
if len(offsetRange) != 2 || offsetRange[0] >= offsetRange[1] {
359+
return strconv.Itoa(index)
360+
}
358361
buf := make([]byte, offsetRange[1]-offsetRange[0])
359362
if _, err := f.sharedStringTemp.ReadAt(buf, int64(offsetRange[0])); err != nil {
360363
return strconv.Itoa(index)

rows_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ func TestRemoveRow(t *testing.T) {
356356

357357
f = NewFile()
358358
formulaType, ref := STCellFormulaTypeShared, "C1:C5"
359-
assert.NoError(t, f.SetCellFormula("Sheet1", "C1", "=A1+B1",
359+
assert.NoError(t, f.SetCellFormula("Sheet1", "C1", "A1+B1",
360360
FormulaOpts{Ref: &ref, Type: &formulaType}))
361361
f.CalcChain = nil
362362
f.Pkg.Store(defaultXMLPathCalcChain, MacintoshCyrillicCharset)

0 commit comments

Comments
 (0)