@@ -30,6 +30,22 @@ import (
3030 "github.com/tiendc/go-deepcopy"
3131)
3232
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+
3349// NewSheet provides the function to create a new sheet by given a worksheet
3450// name and returns the index of the sheets in the workbook after it appended.
3551// Note that when creating a new workbook, the default worksheet named
@@ -2026,7 +2042,7 @@ func (f *File) relsReader(path string) (*xlsxRelationships, error) {
20262042// fillSheetData ensures there are enough rows, and columns in the chosen
20272043// row to accept data. Missing rows are backfilled and given their row number
20282044// 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 ) {
20302046 rowCount := len (ws .SheetData .Row )
20312047 sizeHint := 0
20322048 var ht * float64
@@ -2072,7 +2088,7 @@ func (ws *xlsxWorksheet) makeContiguousColumns(fromRow, toRow, colCount int) {
20722088// of used cells in the worksheet. The range reference is set using the A1
20732089// reference style(e.g., "A1:D5"). Passing an empty range reference will remove
20742090// 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 {
20762092 ws , err := f .workSheetReader (sheet )
20772093 if err != nil {
20782094 return err
@@ -2115,3 +2131,35 @@ func (f *File) GetSheetDimension(sheet string) (string, error) {
21152131 }
21162132 return ref , err
21172133}
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