@@ -30,6 +30,22 @@ import (
30
30
"github.com/tiendc/go-deepcopy"
31
31
)
32
32
33
+ // IgnoredErrorsType is the type of ignored errors.
34
+ type IgnoredErrorsType byte
35
+
36
+ // Ignored errors types enumeration.
37
+ const (
38
+ IgnoredErrorsEvalError = iota
39
+ IgnoredErrorsTwoDigitTextYear
40
+ IgnoredErrorsNumberStoredAsText
41
+ IgnoredErrorsFormula
42
+ IgnoredErrorsFormulaRange
43
+ IgnoredErrorsUnlockedFormula
44
+ IgnoredErrorsEmptyCellReference
45
+ IgnoredErrorsListDataValidation
46
+ IgnoredErrorsCalculatedColumn
47
+ )
48
+
33
49
// NewSheet provides the function to create a new sheet by given a worksheet
34
50
// name and returns the index of the sheets in the workbook after it appended.
35
51
// Note that when creating a new workbook, the default worksheet named
@@ -2026,7 +2042,7 @@ func (f *File) relsReader(path string) (*xlsxRelationships, error) {
2026
2042
// fillSheetData ensures there are enough rows, and columns in the chosen
2027
2043
// row to accept data. Missing rows are backfilled and given their row number
2028
2044
// Uses the last populated row as a hint for the size of the next row to add
2029
- func (ws * xlsxWorksheet ) prepareSheetXML (col int , row int ) {
2045
+ func (ws * xlsxWorksheet ) prepareSheetXML (col , row int ) {
2030
2046
rowCount := len (ws .SheetData .Row )
2031
2047
sizeHint := 0
2032
2048
var ht * float64
@@ -2072,7 +2088,7 @@ func (ws *xlsxWorksheet) makeContiguousColumns(fromRow, toRow, colCount int) {
2072
2088
// of used cells in the worksheet. The range reference is set using the A1
2073
2089
// reference style(e.g., "A1:D5"). Passing an empty range reference will remove
2074
2090
// the used range of the worksheet.
2075
- func (f * File ) SetSheetDimension (sheet string , rangeRef string ) error {
2091
+ func (f * File ) SetSheetDimension (sheet , rangeRef string ) error {
2076
2092
ws , err := f .workSheetReader (sheet )
2077
2093
if err != nil {
2078
2094
return err
@@ -2115,3 +2131,35 @@ func (f *File) GetSheetDimension(sheet string) (string, error) {
2115
2131
}
2116
2132
return ref , err
2117
2133
}
2134
+
2135
+ // AddIgnoredErrors provides the method to ignored error for a range of cells.
2136
+ func (f * File ) AddIgnoredErrors (sheet , rangeRef string , ignoredErrorsType IgnoredErrorsType ) error {
2137
+ ws , err := f .workSheetReader (sheet )
2138
+ if err != nil {
2139
+ return err
2140
+ }
2141
+ if rangeRef == "" {
2142
+ return ErrParameterInvalid
2143
+ }
2144
+ if ws .IgnoredErrors == nil {
2145
+ ws .IgnoredErrors = & xlsxIgnoredErrors {}
2146
+ }
2147
+ ie := map [IgnoredErrorsType ]xlsxIgnoredError {
2148
+ IgnoredErrorsEvalError : {Sqref : rangeRef , EvalError : true },
2149
+ IgnoredErrorsTwoDigitTextYear : {Sqref : rangeRef , TwoDigitTextYear : true },
2150
+ IgnoredErrorsNumberStoredAsText : {Sqref : rangeRef , NumberStoredAsText : true },
2151
+ IgnoredErrorsFormula : {Sqref : rangeRef , Formula : true },
2152
+ IgnoredErrorsFormulaRange : {Sqref : rangeRef , FormulaRange : true },
2153
+ IgnoredErrorsUnlockedFormula : {Sqref : rangeRef , UnlockedFormula : true },
2154
+ IgnoredErrorsEmptyCellReference : {Sqref : rangeRef , EmptyCellReference : true },
2155
+ IgnoredErrorsListDataValidation : {Sqref : rangeRef , ListDataValidation : true },
2156
+ IgnoredErrorsCalculatedColumn : {Sqref : rangeRef , CalculatedColumn : true },
2157
+ }[ignoredErrorsType ]
2158
+ for _ , val := range ws .IgnoredErrors .IgnoredError {
2159
+ if reflect .DeepEqual (val , ie ) {
2160
+ return err
2161
+ }
2162
+ }
2163
+ ws .IgnoredErrors .IgnoredError = append (ws .IgnoredErrors .IgnoredError , ie )
2164
+ return err
2165
+ }
0 commit comments