@@ -637,7 +637,7 @@ func TestGetCellFormula(t *testing.T) {
637
637
// formula cell reference range covered the previous.
638
638
f = NewFile ()
639
639
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 }))
641
641
formula , err = f .GetCellFormula ("Sheet1" , "C2" )
642
642
assert .NoError (t , err )
643
643
assert .Equal (t , "A2+B2" , formula )
@@ -646,7 +646,7 @@ func TestGetCellFormula(t *testing.T) {
646
646
assert .Equal (t , "A6+B6" , formula )
647
647
648
648
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 }))
650
650
formula , err = f .GetCellFormula ("Sheet1" , "C2" )
651
651
assert .NoError (t , err )
652
652
assert .Equal (t , "A2*B2" , formula )
@@ -659,7 +659,7 @@ func TestGetCellFormula(t *testing.T) {
659
659
// formula cell reference range not over the previous.
660
660
f = NewFile ()
661
661
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 }))
663
663
formula , err = f .GetCellFormula ("Sheet1" , "C2" )
664
664
assert .NoError (t , err )
665
665
assert .Equal (t , "A2+B2" , formula )
@@ -668,7 +668,7 @@ func TestGetCellFormula(t *testing.T) {
668
668
assert .Equal (t , "A6+B6" , formula )
669
669
670
670
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 }))
672
672
formula , err = f .GetCellFormula ("Sheet1" , "C2" )
673
673
assert .NoError (t , err )
674
674
assert .Equal (t , "A2*B2" , formula )
@@ -679,7 +679,7 @@ func TestGetCellFormula(t *testing.T) {
679
679
// Test get shared formula after remove refer cell formula
680
680
f = NewFile ()
681
681
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 }))
683
683
684
684
assert .NoError (t , f .SetCellFormula ("Sheet1" , "C2" , "" ))
685
685
@@ -691,7 +691,7 @@ func TestGetCellFormula(t *testing.T) {
691
691
assert .Empty (t , formula )
692
692
693
693
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 }))
695
695
formula , err = f .GetCellFormula ("Sheet1" , "C2" )
696
696
assert .NoError (t , err )
697
697
assert .Equal (t , "A2*B2" , formula )
@@ -791,16 +791,16 @@ func TestSetCellFormula(t *testing.T) {
791
791
assert .NoError (t , f .SetSheetRow ("Sheet1" , fmt .Sprintf ("A%d" , r ), & []interface {}{r , r + 1 }))
792
792
}
793
793
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 }))
795
795
sharedFormulaSpreadsheet := filepath .Join ("test" , "TestSetCellFormula4.xlsx" )
796
796
assert .NoError (t , f .SaveAs (sharedFormulaSpreadsheet ))
797
797
798
798
f , err = OpenFile (sharedFormulaSpreadsheet )
799
799
assert .NoError (t , err )
800
800
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 }))
802
802
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 }))
804
804
assert .NoError (t , f .SaveAs (filepath .Join ("test" , "TestSetCellFormula5.xlsx" )))
805
805
806
806
// Test set table formula for the cells
@@ -810,7 +810,7 @@ func TestSetCellFormula(t *testing.T) {
810
810
}
811
811
assert .NoError (t , f .AddTable ("Sheet1" , & Table {Range : "A1:C2" , Name : "Table1" , StyleName : "TableStyleMedium2" }))
812
812
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 }))
814
814
assert .NoError (t , f .SaveAs (filepath .Join ("test" , "TestSetCellFormula6.xlsx" )))
815
815
816
816
// Test set array formula with invalid cell range reference
@@ -1178,6 +1178,9 @@ func TestSharedStringsError(t *testing.T) {
1178
1178
assert .True (t , ok )
1179
1179
f .tempFiles .Store (defaultXMLPathSharedStrings , "" )
1180
1180
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 ))
1181
1184
// Cleanup undelete temporary files
1182
1185
assert .NoError (t , os .Remove (tempFile .(string )))
1183
1186
// Test reload the file error on set cell value and rich text. The error message was different between macOS and Windows
0 commit comments