unioffice/spreadsheet/datavalidation.go
Vyacheslav Zgordan dd7713e1e3 Functions2 (#348)
* MATCH, IFS, MAXA, MINA
* OFFSET fixed
* ISBLANK, ISERR, ISERROR, ISEVEN ,ISFORMULA, ISNONTEXT, ISNUMBER, ISODD, ISTEXT
* ISLEAPYEAR, ISLOGICAL, ISNA, ISREF
* FIND, FINDB
* SEARCH, SEARCHB
* CONCAT, CONCATENATE
* YEAR, YEARFRAC
* CONCAT is fixed, now TRUE and FALSE are concatenated instead of 1 and 0 in case of boolean results
* NOW, TODAY, TIME, TIMEVALUE
* DATE
* DATEDIF
2019-11-20 23:21:00 +00:00

58 lines
1.6 KiB
Go

// Copyright 2017 FoxyUtils ehf. All rights reserved.
//
// Use of this source code is governed by the terms of the Affero GNU General
// Public License version 3.0 as published by the Free Software Foundation and
// appearing in the file LICENSE included in the packaging of this file. A
// commercial license can be purchased on https://unidoc.io.
package spreadsheet
import (
"github.com/unidoc/unioffice"
"github.com/unidoc/unioffice/schema/soo/sml"
)
// DataValidation controls cell validation
type DataValidation struct {
x *sml.CT_DataValidation
}
// X returns the inner wrapped XML type.
func (d DataValidation) X() *sml.CT_DataValidation {
return d.x
}
func (d DataValidation) clear() {
d.x.Formula1 = unioffice.String("0")
d.x.Formula2 = unioffice.String("0")
}
// SetAllowBlank controls if blank values are accepted.
func (d DataValidation) SetAllowBlank(b bool) {
if !b {
d.x.AllowBlankAttr = nil
} else {
d.x.AllowBlankAttr = unioffice.Bool(true)
}
}
func (d DataValidation) SetList() DataValidationList {
d.clear()
d.x.TypeAttr = sml.ST_DataValidationTypeList
d.x.OperatorAttr = sml.ST_DataValidationOperatorEqual
return DataValidationList{d.x}
}
func (d DataValidation) SetComparison(t DVCompareType, op DVCompareOp) DataValidationCompare {
d.clear()
d.x.TypeAttr = sml.ST_DataValidationType(t)
d.x.OperatorAttr = sml.ST_DataValidationOperator(op)
return DataValidationCompare{d.x}
}
// SetRange sets the cell or range of cells that the validation should apply to.
// It can be a single cell (e.g. "A1") or a range of cells (e.g. "A1:B5")
func (d DataValidation) SetRange(cellRange string) {
d.x.SqrefAttr = sml.ST_Sqref{cellRange}
}