MCPcopy
hub / github.com/qax-os/excelize / NewConditionalStyle

Method NewConditionalStyle

styles.go:1720–1757  ·  view source on GitHub ↗

NewConditionalStyle provides a function to create style for conditional format by given style format. The parameters are the same with the NewStyle function.

(style *Style)

Source from the content-addressed store, hash-verified

1718// format by given style format. The parameters are the same with the NewStyle
1719// function.
1720func (f *File) NewConditionalStyle(style *Style) (int, error) {
1721 f.mu.Lock()
1722 s, err := f.stylesReader()
1723 if err != nil {
1724 f.mu.Unlock()
1725 return 0, err
1726 }
1727 f.mu.Unlock()
1728 fs, err := parseFormatStyleSet(style)
1729 if err != nil {
1730 return 0, err
1731 }
1732 if fs.DecimalPlaces != nil && (*fs.DecimalPlaces < 0 || *fs.DecimalPlaces > 30) {
1733 fs.DecimalPlaces = intPtr(2)
1734 }
1735 dxf := xlsxDxf{
1736 Fill: newFills(fs, false),
1737 }
1738 if fs.Alignment != nil {
1739 dxf.Alignment = newAlignment(fs)
1740 }
1741 if len(fs.Border) > 0 {
1742 dxf.Border = newBorders(fs)
1743 }
1744 if fs.Font != nil {
1745 dxf.Font = fs.Font.newFont()
1746 }
1747 if fs.Protection != nil {
1748 dxf.Protection = newProtection(fs)
1749 }
1750 dxf.NumFmt = newDxfNumFmt(s, style, &dxf)
1751 if s.Dxfs == nil {
1752 s.Dxfs = &xlsxDxfs{}
1753 }
1754 s.Dxfs.Count++
1755 s.Dxfs.Dxfs = append(s.Dxfs.Dxfs, &dxf)
1756 return s.Dxfs.Count - 1, nil
1757}
1758
1759// GetConditionalStyle returns conditional format style definition by specified
1760// style index.

Callers 6

TestConditionalStyleFunction · 0.95
TestDuplicateRowFunction · 0.95
TestConditionalFormatFunction · 0.95

Calls 9

stylesReaderMethod · 0.95
parseFormatStyleSetFunction · 0.85
intPtrFunction · 0.85
newFillsFunction · 0.85
newAlignmentFunction · 0.85
newBordersFunction · 0.85
newProtectionFunction · 0.85
newDxfNumFmtFunction · 0.85
newFontMethod · 0.80

Tested by 6

TestConditionalStyleFunction · 0.76
TestDuplicateRowFunction · 0.76
TestConditionalFormatFunction · 0.76