xlsx-1.1.2.2: Simple and incomplete Excel file parser/writer

Safe Haskell | Safe-Inferred
Language | Haskell2010

Codec.Xlsx.Formatted

Contents

- Lenses
  - Format
  - FormattedCell
  - FormattedCondFmt

Description

Higher level interface for creating styled worksheets

Synopsis

- data FormattedCell = FormattedCell {
  - _formattedCell :: Cell
  - _formattedFormat :: Format
  - _formattedColSpan :: Int
  - _formattedRowSpan :: Int
  }
- data Formatted = Formatted {
  - formattedCellMap :: CellMap
  - formattedStyleSheet :: StyleSheet
  - formattedMerges :: [Range]
  }
- data Format = Format {
  - _formatAlignment :: Maybe Alignment
  - _formatBorder :: Maybe Border
  - _formatFill :: Maybe Fill
  - _formatFont :: Maybe Font
  - _formatNumberFormat :: Maybe NumberFormat
  - _formatProtection :: Maybe Protection
  - _formatPivotButton :: Maybe Bool
  - _formatQuotePrefix :: Maybe Bool
  }
- formatted :: Map (RowIndex, ColumnIndex) FormattedCell -> StyleSheet -> Formatted
- formatWorkbook :: [(Text, Map (RowIndex, ColumnIndex) FormattedCell)] -> StyleSheet -> Xlsx
- toFormattedCells :: CellMap -> [Range] -> StyleSheet -> Map (RowIndex, ColumnIndex) FormattedCell
- data CondFormatted = CondFormatted {
  - condformattedStyleSheet :: StyleSheet
  - condformattedFormattings :: Map SqRef ConditionalFormatting
  }
- conditionallyFormatted :: Map CellRef [FormattedCondFmt] -> StyleSheet -> CondFormatted
- formatAlignment :: Lens' Format (Maybe Alignment)
- formatBorder :: Lens' Format (Maybe Border)
- formatFill :: Lens' Format (Maybe Fill)
- formatFont :: Lens' Format (Maybe Font)
- formatNumberFormat :: Lens' Format (Maybe NumberFormat)
- formatProtection :: Lens' Format (Maybe Protection)
- formatPivotButton :: Lens' Format (Maybe Bool)
- formatQuotePrefix :: Lens' Format (Maybe Bool)
- formattedCell :: Lens' FormattedCell Cell
- formattedFormat :: Lens' FormattedCell Format
- formattedColSpan :: Lens' FormattedCell Int
- formattedRowSpan :: Lens' FormattedCell Int
- condfmtCondition :: Lens' FormattedCondFmt Condition
- condfmtDxf :: Lens' FormattedCondFmt Dxf
- condfmtPriority :: Lens' FormattedCondFmt Int
- condfmtStopIfTrue :: Lens' FormattedCondFmt (Maybe Bool)

# Documentation

data FormattedCell Source #

Cell with formatting. `_cellStyle` property of `_formattedCell` is ignored

See `formatted` for more details.

Constructors

FormattedCell |

Fields

- _formattedCell :: Cell
- _formattedFormat :: Format
- _formattedColSpan :: Int
- _formattedRowSpan :: Int

#### Instances

Instances details

Generic FormattedCell Source # |
Instance details Defined in Codec.Xlsx.Formatted Associated Types type Rep FormattedCell :: Type -> Type Source # Methods from :: FormattedCell -> Rep FormattedCell x Source # to :: Rep FormattedCell x -> FormattedCell Source #
Show FormattedCell Source # |
Instance details Defined in Codec.Xlsx.Formatted Methods showsPrec :: Int -> FormattedCell -> ShowS Source # show :: FormattedCell -> String Source # showList :: [FormattedCell] -> ShowS Source #
Default FormattedCell Source # |
Instance details Defined in Codec.Xlsx.Formatted Methods def :: FormattedCell #
Eq FormattedCell Source # |
Instance details Defined in Codec.Xlsx.Formatted Methods (==) :: FormattedCell -> FormattedCell -> Bool Source # (/=) :: FormattedCell -> FormattedCell -> Bool Source #
type Rep FormattedCell Source # |

Instance details

Defined in Codec.Xlsx.Formatted

type Rep FormattedCell = D1 ('MetaData "FormattedCell" "Codec.Xlsx.Formatted" "xlsx-1.1.2.2-DopzEu8STPN4igxHgE9OUe" 'False) (C1 ('MetaCons "FormattedCell" 'PrefixI 'True) ((S1 ('MetaSel ('Just "_formattedCell") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Cell) :*: S1 ('MetaSel ('Just "_formattedFormat") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Format)) :*: (S1 ('MetaSel ('Just "_formattedColSpan") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int) :*: S1 ('MetaSel ('Just "_formattedRowSpan") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int))))

data Formatted Source #

Result of formatting

See `formatted`

Constructors

Formatted |

Fields

- formattedCellMap :: CellMap

  The final `CellMap`; see `_wsCells`

- formattedStyleSheet :: StyleSheet

  The final stylesheet; see `_xlStyles` (and `renderStyleSheet`)

- formattedMerges :: [Range]

  The final list of cell merges; see `_wsMerges`

#### Instances

Instances details

Generic Formatted Source # |
Instance details Defined in Codec.Xlsx.Formatted Associated Types type Rep Formatted :: Type -> Type Source # Methods from :: Formatted -> Rep Formatted x Source # to :: Rep Formatted x -> Formatted Source #
Show Formatted Source # |
Instance details Defined in Codec.Xlsx.Formatted Methods showsPrec :: Int -> Formatted -> ShowS Source # show :: Formatted -> String Source # showList :: [Formatted] -> ShowS Source #
Eq Formatted Source # |
Instance details Defined in Codec.Xlsx.Formatted Methods (==) :: Formatted -> Formatted -> Bool Source # (/=) :: Formatted -> Formatted -> Bool Source #
type Rep Formatted Source # |

Instance details

Defined in Codec.Xlsx.Formatted

type Rep Formatted = D1 ('MetaData "Formatted" "Codec.Xlsx.Formatted" "xlsx-1.1.2.2-DopzEu8STPN4igxHgE9OUe" 'False) (C1 ('MetaCons "Formatted" 'PrefixI 'True) (S1 ('MetaSel ('Just "formattedCellMap") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 CellMap) :*: (S1 ('MetaSel ('Just "formattedStyleSheet") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 StyleSheet) :*: S1 ('MetaSel ('Just "formattedMerges") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Range]))))

data Format Source #

Formatting options used to format cells

TODOs:

- Add a number format (`_cellXfApplyNumberFormat`, `_cellXfNumFmtId`)
- Add references to the named style sheets (`_cellXfId`)

Constructors

Format |

Fields

- _formatAlignment :: Maybe Alignment
- _formatBorder :: Maybe Border
- _formatFill :: Maybe Fill
- _formatFont :: Maybe Font
- _formatNumberFormat :: Maybe NumberFormat
- _formatProtection :: Maybe Protection
- _formatPivotButton :: Maybe Bool
- _formatQuotePrefix :: Maybe Bool

#### Instances

Instances details

Generic Format Source # |
Instance details Defined in Codec.Xlsx.Formatted Associated Types type Rep Format :: Type -> Type Source # Methods from :: Format -> Rep Format x Source # to :: Rep Format x -> Format Source #
Show Format Source # |
Instance details Defined in Codec.Xlsx.Formatted Methods showsPrec :: Int -> Format -> ShowS Source # show :: Format -> String Source # showList :: [Format] -> ShowS Source #
Default Format Source # |
Instance details Defined in Codec.Xlsx.Formatted Methods def :: Format #
Eq Format Source # |
Instance details Defined in Codec.Xlsx.Formatted Methods (==) :: Format -> Format -> Bool Source # (/=) :: Format -> Format -> Bool Source #
type Rep Format Source # |

Instance details

Defined in Codec.Xlsx.Formatted

type Rep Format = D1 ('MetaData "Format" "Codec.Xlsx.Formatted" "xlsx-1.1.2.2-DopzEu8STPN4igxHgE9OUe" 'False) (C1 ('MetaCons "Format" 'PrefixI 'True) (((S1 ('MetaSel ('Just "_formatAlignment") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Alignment)) :*: S1 ('MetaSel ('Just "_formatBorder") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Border))) :*: (S1 ('MetaSel ('Just "_formatFill") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Fill)) :*: S1 ('MetaSel ('Just "_formatFont") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Font)))) :*: ((S1 ('MetaSel ('Just "_formatNumberFormat") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe NumberFormat)) :*: S1 ('MetaSel ('Just "_formatProtection") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Protection))) :*: (S1 ('MetaSel ('Just "_formatPivotButton") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Bool)) :*: S1 ('MetaSel ('Just "_formatQuotePrefix") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Bool))))))

formatted :: Map (RowIndex, ColumnIndex) FormattedCell -> StyleSheet -> Formatted Source #

Higher level API for creating formatted documents

Creating formatted Excel spreadsheets using the `Cell` datatype directly, even with the support for the `StyleSheet` datatype, is fairly painful. This has a number of causes:

- The `Cell` datatype wants an `Int` for the style, which is supposed to point into the `_styleSheetCellXfs` part of a stylesheet. However, this can be difficult to work with, as it requires manual tracking of cell style IDs, which in turns requires manual tracking of font IDs, border IDs, etc.
- Row-span and column-span properties are set on the worksheet as a whole (`wsMerges`) rather than on individual cells.
- Excel does not correctly deal with borders on cells that span multiple columns or rows. Instead, these rows must be set on all the edge cells in the block. Again, this means that this becomes a global property of the spreadsheet rather than properties of individual cells.

This function deals with all these problems. Given a map of `FormattedCell`s, which refer directly to `Font`s, `Border`s, etc. (rather than font IDs, border IDs, etc.), and an initial stylesheet, it recovers all possible sharing, constructs IDs, and then constructs the final `CellMap`, as well as the final stylesheet and list of merges.

If you don't already have a `StyleSheet` you want to use as starting point then `minimalStyleSheet` is a good choice.

formatWorkbook :: [(Text, Map (RowIndex, ColumnIndex) FormattedCell)] -> StyleSheet -> Xlsx Source #

Build an `Xlsx`, render provided cells as per the `StyleSheet`.

toFormattedCells :: CellMap -> [Range] -> StyleSheet -> Map (RowIndex, ColumnIndex) FormattedCell Source #

reverse to `formatted` which allows to get a map of formatted cells from an existing worksheet and its workbook's style sheet

data CondFormatted Source #

Constructors

CondFormatted |

Fields

- condformattedStyleSheet :: StyleSheet

  The resulting stylesheet

- condformattedFormattings :: Map SqRef ConditionalFormatting

  The final map of conditional formatting rules applied to ranges

#### Instances

Instances details

Generic CondFormatted Source # |
Instance details Defined in Codec.Xlsx.Formatted Associated Types type Rep CondFormatted :: Type -> Type Source # Methods from :: CondFormatted -> Rep CondFormatted x Source # to :: Rep CondFormatted x -> CondFormatted Source #
Show CondFormatted Source # |
Instance details Defined in Codec.Xlsx.Formatted Methods showsPrec :: Int -> CondFormatted -> ShowS Source # show :: CondFormatted -> String Source # showList :: [CondFormatted] -> ShowS Source #
Eq CondFormatted Source # |
Instance details Defined in Codec.Xlsx.Formatted Methods (==) :: CondFormatted -> CondFormatted -> Bool Source # (/=) :: CondFormatted -> CondFormatted -> Bool Source #
type Rep CondFormatted Source # |

Instance details

Defined in Codec.Xlsx.Formatted

type Rep CondFormatted = D1 ('MetaData "CondFormatted" "Codec.Xlsx.Formatted" "xlsx-1.1.2.2-DopzEu8STPN4igxHgE9OUe" 'False) (C1 ('MetaCons "CondFormatted" 'PrefixI 'True) (S1 ('MetaSel ('Just "condformattedStyleSheet") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 StyleSheet) :*: S1 ('MetaSel ('Just "condformattedFormattings") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Map SqRef ConditionalFormatting))))

conditionallyFormatted :: Map CellRef [FormattedCondFmt] -> StyleSheet -> CondFormatted Source #

# Lenses

## Format

formatAlignment :: Lens' Format (Maybe Alignment) Source #

formatBorder :: Lens' Format (Maybe Border) Source #

formatFill :: Lens' Format (Maybe Fill) Source #

formatFont :: Lens' Format (Maybe Font) Source #

formatNumberFormat :: Lens' Format (Maybe NumberFormat) Source #

formatProtection :: Lens' Format (Maybe Protection) Source #

formatPivotButton :: Lens' Format (Maybe Bool) Source #

formatQuotePrefix :: Lens' Format (Maybe Bool) Source #

## FormattedCell

formattedCell :: Lens' FormattedCell Cell Source #

formattedFormat :: Lens' FormattedCell Format Source #

formattedColSpan :: Lens' FormattedCell Int Source #

formattedRowSpan :: Lens' FormattedCell Int Source #

## FormattedCondFmt

condfmtCondition :: Lens' FormattedCondFmt Condition Source #

condfmtDxf :: Lens' FormattedCondFmt Dxf Source #

condfmtPriority :: Lens' FormattedCondFmt Int Source #

condfmtStopIfTrue :: Lens' FormattedCondFmt (Maybe Bool) Source #