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)
| 1718 | // format by given style format. The parameters are the same with the NewStyle |
| 1719 | // function. |
| 1720 | func (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. |