    {-# LANGUAGE CPP #-}
    {-# LANGUAGE NoMonomorphismRestriction #-}
    {-# LANGUAGE OverloadedStrings #-}
    {-# LANGUAGE RecordWildCards #-}
    {-# LANGUAGE TemplateHaskell #-}
    {-# LANGUAGE DeriveGeneric #-}
    {-# LANGUAGE RankNTypes          #-}

    module Codec.Xlsx.Types (
        -- * The main types
        Xlsx(..)
        , Styles(..)
        , DefinedNames(..)
        , ColumnsProperties(..)
        , PageSetup(..)
        , Worksheet(..)
        , SheetState(..)
        , CellMap
        , CellValue(..)
        , CellFormula(..)
        , FormulaExpression(..)
        , Cell.SharedFormulaIndex(..)
        , Cell.SharedFormulaOptions(..)
        , Cell(..)
        , RowHeight(..)
        , RowProperties (..)
        -- * Lenses
        -- ** Workbook
        , xlSheets
        , xlStyles
        , xlDefinedNames
        , xlCustomProperties
        , xlDateBase
        -- ** Worksheet
        , wsColumnsProperties
        , wsRowPropertiesMap
        , wsCells
        , wsDrawing
        , wsMerges
        , wsSheetViews
        , wsPageSetup
        , wsConditionalFormattings
        , wsDataValidations
        , wsPivotTables
        , wsAutoFilter
        , wsTables
        , wsProtection
        , wsSharedFormulas
        , wsState
        -- ** Cells
        , Cell.cellValue
        , Cell.cellStyle
        , Cell.cellComment
        , Cell.cellFormula
        -- ** Row properties
        , rowHeightLens
        , _CustomHeight
        , _AutomaticHeight
        -- * Style helpers
        , emptyStyles
        , renderStyleSheet
        , parseStyleSheet
        -- * Misc
        , simpleCellFormula
        , sharedFormulaByIndex
        , def
        , toRows
        , fromRows
        , module X
        ) where

    import Control.Exception (SomeException, toException)
    #ifdef USE_MICROLENS
    import Lens.Micro.TH
    import Data.Profunctor(dimap)
    import Data.Profunctor.Choice
    #else
    #endif
    import Control.DeepSeq (NFData)
    import qualified Data.ByteString.Lazy as L
    import Data.Default
    import Data.Function (on)
    import Data.List (groupBy)
    import Data.Map (Map)
    import qualified Data.Map as M
    import Data.Maybe (catMaybes, isJust)
    import Data.Text (Text)
    import GHC.Generics (Generic)
    import Text.XML (parseLBS, renderLBS)
    import Text.XML.Cursor

    import Codec.Xlsx.Parser.Internal
    import Codec.Xlsx.Types.AutoFilter as X
    import Codec.Xlsx.Types.Cell as Cell
    import Codec.Xlsx.Types.Comment as X
    import Codec.Xlsx.Types.Common as X
    import Codec.Xlsx.Types.ConditionalFormatting as X
    import Codec.Xlsx.Types.DataValidation as X
    import Codec.Xlsx.Types.Drawing as X
    import Codec.Xlsx.Types.Drawing.Chart as X
    import Codec.Xlsx.Types.Drawing.Common as X
    import Codec.Xlsx.Types.PageSetup as X
    import Codec.Xlsx.Types.PivotTable as X
    import Codec.Xlsx.Types.Protection as X
    import Codec.Xlsx.Types.RichText as X
    import Codec.Xlsx.Types.SheetViews as X
    import Codec.Xlsx.Types.StyleSheet as X
    import Codec.Xlsx.Types.Table as X
    import Codec.Xlsx.Types.Variant as X
    import Codec.Xlsx.Writer.Internal
    #ifdef USE_MICROLENS
    import Lens.Micro
    #else
    import Control.Lens (lens, Lens', makeLenses)
    import Control.Lens.TH (makePrisms)
    #endif

    -- | Height of a row in points (1/72in)
    data RowHeight
      = CustomHeight    !Double
        -- ^ Row height is set by the user
      | AutomaticHeight !Double
        -- ^ Row height is set automatically by the program
      deriving (RowHeight -> RowHeight -> Bool
    (RowHeight -> RowHeight -> Bool)
    -> (RowHeight -> RowHeight -> Bool) -> Eq RowHeight
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: RowHeight -> RowHeight -> Bool
    == :: RowHeight -> RowHeight -> Bool
    $c/= :: RowHeight -> RowHeight -> Bool
    /= :: RowHeight -> RowHeight -> Bool
    Eq, Eq RowHeight
    Eq RowHeight =>
    (RowHeight -> RowHeight -> Ordering)
    -> (RowHeight -> RowHeight -> Bool)
    -> (RowHeight -> RowHeight -> Bool)
    -> (RowHeight -> RowHeight -> Bool)
    -> (RowHeight -> RowHeight -> Bool)
    -> (RowHeight -> RowHeight -> RowHeight)
    -> (RowHeight -> RowHeight -> RowHeight)
    -> Ord RowHeight
    RowHeight -> RowHeight -> Bool
    RowHeight -> RowHeight -> Ordering
    RowHeight -> RowHeight -> RowHeight
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: RowHeight -> RowHeight -> Ordering
    compare :: RowHeight -> RowHeight -> Ordering
    $c< :: RowHeight -> RowHeight -> Bool
    < :: RowHeight -> RowHeight -> Bool
    $c<= :: RowHeight -> RowHeight -> Bool
    <= :: RowHeight -> RowHeight -> Bool
    $c> :: RowHeight -> RowHeight -> Bool
    > :: RowHeight -> RowHeight -> Bool
    $c>= :: RowHeight -> RowHeight -> Bool
    >= :: RowHeight -> RowHeight -> Bool
    $cmax :: RowHeight -> RowHeight -> RowHeight
    max :: RowHeight -> RowHeight -> RowHeight
    $cmin :: RowHeight -> RowHeight -> RowHeight
    min :: RowHeight -> RowHeight -> RowHeight
    Ord, Int -> RowHeight -> ShowS
    [RowHeight] -> ShowS
    RowHeight -> String
    (Int -> RowHeight -> ShowS)
    -> (RowHeight -> String)
    -> ([RowHeight] -> ShowS)
    -> Show RowHeight
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> RowHeight -> ShowS
    showsPrec :: Int -> RowHeight -> ShowS
    $cshow :: RowHeight -> String
    show :: RowHeight -> String
    $cshowList :: [RowHeight] -> ShowS
    showList :: [RowHeight] -> ShowS
    Show, ReadPrec [RowHeight]
    ReadPrec RowHeight
    Int -> ReadS RowHeight
    ReadS [RowHeight]
    (Int -> ReadS RowHeight)
    -> ReadS [RowHeight]
    -> ReadPrec RowHeight
    -> ReadPrec [RowHeight]
    -> Read RowHeight
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    $creadsPrec :: Int -> ReadS RowHeight
    readsPrec :: Int -> ReadS RowHeight
    $creadList :: ReadS [RowHeight]
    readList :: ReadS [RowHeight]
    $creadPrec :: ReadPrec RowHeight
    readPrec :: ReadPrec RowHeight
    $creadListPrec :: ReadPrec [RowHeight]
    readListPrec :: ReadPrec [RowHeight]
    Read, (forall x. RowHeight -> Rep RowHeight x)
    -> (forall x. Rep RowHeight x -> RowHeight) -> Generic RowHeight
    forall x. Rep RowHeight x -> RowHeight
    forall x. RowHeight -> Rep RowHeight x
    forall a.
    (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
    $cfrom :: forall x. RowHeight -> Rep RowHeight x
    from :: forall x. RowHeight -> Rep RowHeight x
    $cto :: forall x. Rep RowHeight x -> RowHeight
    to :: forall x. Rep RowHeight x -> RowHeight
    Generic)
    instance NFData RowHeight

    #ifdef USE_MICROLENS
    -- Since micro-lens denies the existence of prisms,
    -- I pasted the splice that's generated from makePrisms,
    -- then I copied over the definitions from Control.Lens for the prism
    -- function as well.
    type Prism s t a b = forall p f. (Choice p, Applicative f) => p a (f b) -> p s (f t)
    type Prism' s a = Prism s s a a

    prism :: (b -> t) -> (s -> Either t a) -> Prism s t a b
    prism bt seta = dimap seta (either pure (fmap bt)) . right'

    _CustomHeight :: Prism' RowHeight Double
    _CustomHeight
      = (prism (\ x1_a4xgd -> CustomHeight x1_a4xgd))
          (\ x_a4xge
             -> case x_a4xge of
                  CustomHeight y1_a4xgf -> Right y1_a4xgf
                  _ -> Left x_a4xge)
    {-# INLINE _CustomHeight #-}

    _AutomaticHeight :: Prism' RowHeight Double
    _AutomaticHeight
      = (prism (\ x1_a4xgg -> AutomaticHeight x1_a4xgg))
          (\ x_a4xgh
             -> case x_a4xgh of
                  AutomaticHeight y1_a4xgi -> Right y1_a4xgi
                  _ -> Left x_a4xgh)
    {-# INLINE _AutomaticHeight #-}

    #else
    makePrisms ''RowHeight
    #endif

    -- | Properties of a row. See §18.3.1.73 "row (Row)" for more details
    data RowProperties = RowProps
      { RowProperties -> Maybe RowHeight
    rowHeight       :: Maybe RowHeight
        -- ^ Row height in points
      , RowProperties -> Maybe Int
    rowStyle        :: Maybe Int
        -- ^ Style to be applied to row
      , RowProperties -> Bool
    rowHidden       :: Bool
        -- ^ Whether row is visible or not
      } deriving (RowProperties -> RowProperties -> Bool
    (RowProperties -> RowProperties -> Bool)
    -> (RowProperties -> RowProperties -> Bool) -> Eq RowProperties
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: RowProperties -> RowProperties -> Bool
    == :: RowProperties -> RowProperties -> Bool
    $c/= :: RowProperties -> RowProperties -> Bool
    /= :: RowProperties -> RowProperties -> Bool
    Eq, Eq RowProperties
    Eq RowProperties =>
    (RowProperties -> RowProperties -> Ordering)
    -> (RowProperties -> RowProperties -> Bool)
    -> (RowProperties -> RowProperties -> Bool)
    -> (RowProperties -> RowProperties -> Bool)
    -> (RowProperties -> RowProperties -> Bool)
    -> (RowProperties -> RowProperties -> RowProperties)
    -> (RowProperties -> RowProperties -> RowProperties)
    -> Ord RowProperties
    RowProperties -> RowProperties -> Bool
    RowProperties -> RowProperties -> Ordering
    RowProperties -> RowProperties -> RowProperties
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: RowProperties -> RowProperties -> Ordering
    compare :: RowProperties -> RowProperties -> Ordering
    $c< :: RowProperties -> RowProperties -> Bool
    < :: RowProperties -> RowProperties -> Bool
    $c<= :: RowProperties -> RowProperties -> Bool
    <= :: RowProperties -> RowProperties -> Bool
    $c> :: RowProperties -> RowProperties -> Bool
    > :: RowProperties -> RowProperties -> Bool
    $c>= :: RowProperties -> RowProperties -> Bool
    >= :: RowProperties -> RowProperties -> Bool
    $cmax :: RowProperties -> RowProperties -> RowProperties
    max :: RowProperties -> RowProperties -> RowProperties
    $cmin :: RowProperties -> RowProperties -> RowProperties
    min :: RowProperties -> RowProperties -> RowProperties
    Ord, Int -> RowProperties -> ShowS
    [RowProperties] -> ShowS
    RowProperties -> String
    (Int -> RowProperties -> ShowS)
    -> (RowProperties -> String)
    -> ([RowProperties] -> ShowS)
    -> Show RowProperties
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> RowProperties -> ShowS
    showsPrec :: Int -> RowProperties -> ShowS
    $cshow :: RowProperties -> String
    show :: RowProperties -> String
    $cshowList :: [RowProperties] -> ShowS
    showList :: [RowProperties] -> ShowS
    Show, ReadPrec [RowProperties]
    ReadPrec RowProperties
    Int -> ReadS RowProperties
    ReadS [RowProperties]
    (Int -> ReadS RowProperties)
    -> ReadS [RowProperties]
    -> ReadPrec RowProperties
    -> ReadPrec [RowProperties]
    -> Read RowProperties
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    $creadsPrec :: Int -> ReadS RowProperties
    readsPrec :: Int -> ReadS RowProperties
    $creadList :: ReadS [RowProperties]
    readList :: ReadS [RowProperties]
    $creadPrec :: ReadPrec RowProperties
    readPrec :: ReadPrec RowProperties
    $creadListPrec :: ReadPrec [RowProperties]
    readListPrec :: ReadPrec [RowProperties]
    Read, (forall x. RowProperties -> Rep RowProperties x)
    -> (forall x. Rep RowProperties x -> RowProperties)
    -> Generic RowProperties
    forall x. Rep RowProperties x -> RowProperties
    forall x. RowProperties -> Rep RowProperties x
    forall a.
    (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
    $cfrom :: forall x. RowProperties -> Rep RowProperties x
    from :: forall x. RowProperties -> Rep RowProperties x
    $cto :: forall x. Rep RowProperties x -> RowProperties
    to :: forall x. Rep RowProperties x -> RowProperties
    Generic)
    instance NFData RowProperties

    rowHeightLens :: Lens' RowProperties (Maybe RowHeight)
    rowHeightLens :: Lens' RowProperties (Maybe RowHeight)
    rowHeightLens = (RowProperties -> Maybe RowHeight)
    -> (RowProperties -> Maybe RowHeight -> RowProperties)
    -> Lens' RowProperties (Maybe RowHeight)
    forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
    lens RowProperties -> Maybe RowHeight
    rowHeight ((RowProperties -> Maybe RowHeight -> RowProperties)
     -> Lens' RowProperties (Maybe RowHeight))
    -> (RowProperties -> Maybe RowHeight -> RowProperties)
    -> Lens' RowProperties (Maybe RowHeight)
    forall a b. (a -> b) -> a -> b
    $ \RowProperties
    x Maybe RowHeight
    y -> RowProperties
    x{rowHeight=y}

    instance Default RowProperties where
      def :: RowProperties
    def = RowProps { rowHeight :: Maybe RowHeight
    rowHeight       = Maybe RowHeight
    forall a. Maybe a
    Nothing
                     , rowStyle :: Maybe Int
    rowStyle        = Maybe Int
    forall a. Maybe a
    Nothing
                     , rowHidden :: Bool
    rowHidden       = Bool
    False
                     }

    -- | Column range (from cwMin to cwMax) properties
    data ColumnsProperties = ColumnsProperties
      { ColumnsProperties -> Int
    cpMin :: Int
      -- ^ First column affected by this 'ColumnWidth' record.
      , ColumnsProperties -> Int
    cpMax :: Int
      -- ^ Last column affected by this 'ColumnWidth' record.
      , ColumnsProperties -> Maybe Double
    cpWidth :: Maybe Double
      -- ^ Column width measured as the number of characters of the
      -- maximum digit width of the numbers 0, 1, 2, ..., 9 as rendered in
      -- the normal style's font.
      --
      -- See longer description in Section 18.3.1.13 "col (Column Width &
      -- Formatting)" (p. 1605)
      , ColumnsProperties -> Maybe Int
    cpStyle :: Maybe Int
      -- ^ Default style for the affected column(s). Affects cells not yet
      -- allocated in the column(s).  In other words, this style applies
      -- to new columns.
      , ColumnsProperties -> Bool
    cpHidden :: Bool
      -- ^ Flag indicating if the affected column(s) are hidden on this
      -- worksheet.
      , ColumnsProperties -> Bool
    cpCollapsed :: Bool
      -- ^ Flag indicating if the outlining of the affected column(s) is
      -- in the collapsed state.
      , ColumnsProperties -> Bool
    cpBestFit :: Bool
      -- ^ Flag indicating if the specified column(s) is set to 'best
      -- fit'.
      } deriving (ColumnsProperties -> ColumnsProperties -> Bool
    (ColumnsProperties -> ColumnsProperties -> Bool)
    -> (ColumnsProperties -> ColumnsProperties -> Bool)
    -> Eq ColumnsProperties
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: ColumnsProperties -> ColumnsProperties -> Bool
    == :: ColumnsProperties -> ColumnsProperties -> Bool
    $c/= :: ColumnsProperties -> ColumnsProperties -> Bool
    /= :: ColumnsProperties -> ColumnsProperties -> Bool
    Eq, Int -> ColumnsProperties -> ShowS
    [ColumnsProperties] -> ShowS
    ColumnsProperties -> String
    (Int -> ColumnsProperties -> ShowS)
    -> (ColumnsProperties -> String)
    -> ([ColumnsProperties] -> ShowS)
    -> Show ColumnsProperties
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> ColumnsProperties -> ShowS
    showsPrec :: Int -> ColumnsProperties -> ShowS
    $cshow :: ColumnsProperties -> String
    show :: ColumnsProperties -> String
    $cshowList :: [ColumnsProperties] -> ShowS
    showList :: [ColumnsProperties] -> ShowS
    Show, (forall x. ColumnsProperties -> Rep ColumnsProperties x)
    -> (forall x. Rep ColumnsProperties x -> ColumnsProperties)
    -> Generic ColumnsProperties
    forall x. Rep ColumnsProperties x -> ColumnsProperties
    forall x. ColumnsProperties -> Rep ColumnsProperties x
    forall a.
    (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
    $cfrom :: forall x. ColumnsProperties -> Rep ColumnsProperties x
    from :: forall x. ColumnsProperties -> Rep ColumnsProperties x
    $cto :: forall x. Rep ColumnsProperties x -> ColumnsProperties
    to :: forall x. Rep ColumnsProperties x -> ColumnsProperties
    Generic)
    instance NFData ColumnsProperties

    instance FromCursor ColumnsProperties where
      fromCursor :: Cursor -> [ColumnsProperties]
    fromCursor Cursor
    c = do
        Int
    cpMin <- Name -> Cursor -> [Int]
    forall a. FromAttrVal a => Name -> Cursor -> [a]
    fromAttribute Name
    "min" Cursor
    c
        Int
    cpMax <- Name -> Cursor -> [Int]
    forall a. FromAttrVal a => Name -> Cursor -> [a]
    fromAttribute Name
    "max" Cursor
    c
        Maybe Double
    cpWidth <- Name -> Cursor -> [Maybe Double]
    forall a. FromAttrVal a => Name -> Cursor -> [Maybe a]
    maybeAttribute Name
    "width" Cursor
    c
        Maybe Int
    cpStyle <- Name -> Cursor -> [Maybe Int]
    forall a. FromAttrVal a => Name -> Cursor -> [Maybe a]
    maybeAttribute Name
    "style" Cursor
    c
        Bool
    cpHidden <- Name -> Bool -> Cursor -> [Bool]
    forall a. FromAttrVal a => Name -> a -> Cursor -> [a]
    fromAttributeDef Name
    "hidden" Bool
    False Cursor
    c
        Bool
    cpCollapsed <- Name -> Bool -> Cursor -> [Bool]
    forall a. FromAttrVal a => Name -> a -> Cursor -> [a]
    fromAttributeDef Name
    "collapsed" Bool
    False Cursor
    c
        Bool
    cpBestFit <- Name -> Bool -> Cursor -> [Bool]
    forall a. FromAttrVal a => Name -> a -> Cursor -> [a]
    fromAttributeDef Name
    "bestFit" Bool
    False Cursor
    c
        ColumnsProperties -> [ColumnsProperties]
    forall a. a -> [a]
    forall (m :: * -> *) a. Monad m => a -> m a
    return ColumnsProperties {Bool
    Int
    Maybe Double
    Maybe Int
    cpMin :: Int
    cpMax :: Int
    cpWidth :: Maybe Double
    cpStyle :: Maybe Int
    cpHidden :: Bool
    cpCollapsed :: Bool
    cpBestFit :: Bool
    cpMin :: Int
    cpMax :: Int
    cpWidth :: Maybe Double
    cpStyle :: Maybe Int
    cpHidden :: Bool
    cpCollapsed :: Bool
    cpBestFit :: Bool
    ..}

    instance FromXenoNode ColumnsProperties where
      fromXenoNode :: Node -> Either Text ColumnsProperties
    fromXenoNode Node
    root = Node
    -> AttrParser ColumnsProperties -> Either Text ColumnsProperties
    forall a. Node -> AttrParser a -> Either Text a
    parseAttributes Node
    root (AttrParser ColumnsProperties -> Either Text ColumnsProperties)
    -> AttrParser ColumnsProperties -> Either Text ColumnsProperties
    forall a b. (a -> b) -> a -> b
    $ do
        Int
    cpMin <- ByteString -> AttrParser Int
    forall a. FromAttrBs a => ByteString -> AttrParser a
    fromAttr ByteString
    "min"
        Int
    cpMax <- ByteString -> AttrParser Int
    forall a. FromAttrBs a => ByteString -> AttrParser a
    fromAttr ByteString
    "max"
        Maybe Double
    cpWidth <- ByteString -> AttrParser (Maybe Double)
    forall a. FromAttrBs a => ByteString -> AttrParser (Maybe a)
    maybeAttr ByteString
    "width"
        Maybe Int
    cpStyle <- ByteString -> AttrParser (Maybe Int)
    forall a. FromAttrBs a => ByteString -> AttrParser (Maybe a)
    maybeAttr ByteString
    "style"
        Bool
    cpHidden <- ByteString -> Bool -> AttrParser Bool
    forall a. FromAttrBs a => ByteString -> a -> AttrParser a
    fromAttrDef ByteString
    "hidden" Bool
    False
        Bool
    cpCollapsed <- ByteString -> Bool -> AttrParser Bool
    forall a. FromAttrBs a => ByteString -> a -> AttrParser a
    fromAttrDef ByteString
    "collapsed" Bool
    False
        Bool
    cpBestFit <- ByteString -> Bool -> AttrParser Bool
    forall a. FromAttrBs a => ByteString -> a -> AttrParser a
    fromAttrDef ByteString
    "bestFit" Bool
    False
        ColumnsProperties -> AttrParser ColumnsProperties
    forall a. a -> AttrParser a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ColumnsProperties {Bool
    Int
    Maybe Double
    Maybe Int
    cpMin :: Int
    cpMax :: Int
    cpWidth :: Maybe Double
    cpStyle :: Maybe Int
    cpHidden :: Bool
    cpCollapsed :: Bool
    cpBestFit :: Bool
    cpMin :: Int
    cpMax :: Int
    cpWidth :: Maybe Double
    cpStyle :: Maybe Int
    cpHidden :: Bool
    cpCollapsed :: Bool
    cpBestFit :: Bool
    ..}

    -- | Sheet visibility state
    -- cf. Ecma Office Open XML Part 1:
    -- 18.18.68 ST_SheetState (Sheet Visibility Types)
    -- * "visible"
    --     Indicates the sheet is visible (default)
    -- * "hidden"
    --     Indicates the workbook window is hidden, but can be shown by the user via the user interface.
    -- * "veryHidden"
    --     Indicates the sheet is hidden and cannot be shown in the user interface (UI). This state is only available programmatically.
    data SheetState =
      Visible -- ^ state="visible"
      | Hidden -- ^ state="hidden"
      | VeryHidden -- ^ state="veryHidden"
      deriving (SheetState -> SheetState -> Bool
    (SheetState -> SheetState -> Bool)
    -> (SheetState -> SheetState -> Bool) -> Eq SheetState
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: SheetState -> SheetState -> Bool
    == :: SheetState -> SheetState -> Bool
    $c/= :: SheetState -> SheetState -> Bool
    /= :: SheetState -> SheetState -> Bool
    Eq, Int -> SheetState -> ShowS
    [SheetState] -> ShowS
    SheetState -> String
    (Int -> SheetState -> ShowS)
    -> (SheetState -> String)
    -> ([SheetState] -> ShowS)
    -> Show SheetState
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> SheetState -> ShowS
    showsPrec :: Int -> SheetState -> ShowS
    $cshow :: SheetState -> String
    show :: SheetState -> String
    $cshowList :: [SheetState] -> ShowS
    showList :: [SheetState] -> ShowS
    Show, (forall x. SheetState -> Rep SheetState x)
    -> (forall x. Rep SheetState x -> SheetState) -> Generic SheetState
    forall x. Rep SheetState x -> SheetState
    forall x. SheetState -> Rep SheetState x
    forall a.
    (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
    $cfrom :: forall x. SheetState -> Rep SheetState x
    from :: forall x. SheetState -> Rep SheetState x
    $cto :: forall x. Rep SheetState x -> SheetState
    to :: forall x. Rep SheetState x -> SheetState
    Generic)

    instance NFData SheetState

    instance Default SheetState where
      def :: SheetState
    def = SheetState
    Visible

    instance FromAttrVal SheetState where
        fromAttrVal :: Reader SheetState
    fromAttrVal Text
    "visible"    = SheetState -> Either String (SheetState, Text)
    forall a. a -> Either String (a, Text)
    readSuccess SheetState
    Visible
        fromAttrVal Text
    "hidden"     = SheetState -> Either String (SheetState, Text)
    forall a. a -> Either String (a, Text)
    readSuccess SheetState
    Hidden
        fromAttrVal Text
    "veryHidden" = SheetState -> Either String (SheetState, Text)
    forall a. a -> Either String (a, Text)
    readSuccess SheetState
    VeryHidden
        fromAttrVal Text
    t            = Text -> Reader SheetState
    forall a. Text -> Text -> Either String (a, Text)
    invalidText Text
    "SheetState" Text
    t

    instance FromAttrBs SheetState where
        fromAttrBs :: ByteString -> Either Text SheetState
    fromAttrBs ByteString
    "visible"    = SheetState -> Either Text SheetState
    forall a. a -> Either Text a
    forall (m :: * -> *) a. Monad m => a -> m a
    return SheetState
    Visible
        fromAttrBs ByteString
    "hidden"     = SheetState -> Either Text SheetState
    forall a. a -> Either Text a
    forall (m :: * -> *) a. Monad m => a -> m a
    return SheetState
    Hidden
        fromAttrBs ByteString
    "veryHidden" = SheetState -> Either Text SheetState
    forall a. a -> Either Text a
    forall (m :: * -> *) a. Monad m => a -> m a
    return SheetState
    VeryHidden
        fromAttrBs ByteString
    t            = Text -> ByteString -> Either Text SheetState
    forall a. Text -> ByteString -> Either Text a
    unexpectedAttrBs Text
    "SheetState" ByteString
    t

    instance ToAttrVal SheetState where
        toAttrVal :: SheetState -> Text
    toAttrVal SheetState
    Visible    = Text
    "visible"
        toAttrVal SheetState
    Hidden     = Text
    "hidden"
        toAttrVal SheetState
    VeryHidden = Text
    "veryHidden"

    -- | Xlsx worksheet
    data Worksheet = Worksheet
      { Worksheet -> [ColumnsProperties]
    _wsColumnsProperties :: [ColumnsProperties] -- ^ column widths
      , Worksheet -> Map RowIndex RowProperties
    _wsRowPropertiesMap :: Map RowIndex RowProperties
        -- ^ custom row properties (height, style) map
      , Worksheet -> CellMap
    _wsCells :: CellMap -- ^ data mapped by (row, column) pairs
      , Worksheet -> Maybe Drawing
    _wsDrawing :: Maybe Drawing -- ^ SpreadsheetML Drawing
      , Worksheet -> [Range]
    _wsMerges :: [Range] -- ^ list of cell merges
      , Worksheet -> Maybe [SheetView]
    _wsSheetViews :: Maybe [SheetView]
      , Worksheet -> Maybe PageSetup
    _wsPageSetup :: Maybe PageSetup
      , Worksheet -> Map SqRef ConditionalFormatting
    _wsConditionalFormattings :: Map SqRef ConditionalFormatting
      , Worksheet -> Map SqRef DataValidation
    _wsDataValidations :: Map SqRef DataValidation
      , Worksheet -> [PivotTable]
    _wsPivotTables :: [PivotTable]
      , Worksheet -> Maybe AutoFilter
    _wsAutoFilter :: Maybe AutoFilter
      , Worksheet -> [Table]
    _wsTables :: [Table]
      , Worksheet -> Maybe SheetProtection
    _wsProtection :: Maybe SheetProtection
      , Worksheet -> Map SharedFormulaIndex SharedFormulaOptions
    _wsSharedFormulas :: Map SharedFormulaIndex SharedFormulaOptions
      , Worksheet -> SheetState
    _wsState :: SheetState
      } deriving (Worksheet -> Worksheet -> Bool
    (Worksheet -> Worksheet -> Bool)
    -> (Worksheet -> Worksheet -> Bool) -> Eq Worksheet
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: Worksheet -> Worksheet -> Bool
    == :: Worksheet -> Worksheet -> Bool
    $c/= :: Worksheet -> Worksheet -> Bool
    /= :: Worksheet -> Worksheet -> Bool
    Eq, Int -> Worksheet -> ShowS
    [Worksheet] -> ShowS
    Worksheet -> String
    (Int -> Worksheet -> ShowS)
    -> (Worksheet -> String)
    -> ([Worksheet] -> ShowS)
    -> Show Worksheet
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> Worksheet -> ShowS
    showsPrec :: Int -> Worksheet -> ShowS
    $cshow :: Worksheet -> String
    show :: Worksheet -> String
    $cshowList :: [Worksheet] -> ShowS
    showList :: [Worksheet] -> ShowS
    Show, (forall x. Worksheet -> Rep Worksheet x)
    -> (forall x. Rep Worksheet x -> Worksheet) -> Generic Worksheet
    forall x. Rep Worksheet x -> Worksheet
    forall x. Worksheet -> Rep Worksheet x
    forall a.
    (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
    $cfrom :: forall x. Worksheet -> Rep Worksheet x
    from :: forall x. Worksheet -> Rep Worksheet x
    $cto :: forall x. Rep Worksheet x -> Worksheet
    to :: forall x. Rep Worksheet x -> Worksheet
    Generic)
    instance NFData Worksheet

    makeLenses ''Worksheet

    instance Default Worksheet where
      def :: Worksheet
    def =
        Worksheet
        { _wsColumnsProperties :: [ColumnsProperties]
    _wsColumnsProperties = []
        , _wsRowPropertiesMap :: Map RowIndex RowProperties
    _wsRowPropertiesMap = Map RowIndex RowProperties
    forall k a. Map k a
    M.empty
        , _wsCells :: CellMap
    _wsCells = CellMap
    forall k a. Map k a
    M.empty
        , _wsDrawing :: Maybe Drawing
    _wsDrawing = Maybe Drawing
    forall a. Maybe a
    Nothing
        , _wsMerges :: [Range]
    _wsMerges = []
        , _wsSheetViews :: Maybe [SheetView]
    _wsSheetViews = Maybe [SheetView]
    forall a. Maybe a
    Nothing
        , _wsPageSetup :: Maybe PageSetup
    _wsPageSetup = Maybe PageSetup
    forall a. Maybe a
    Nothing
        , _wsConditionalFormattings :: Map SqRef ConditionalFormatting
    _wsConditionalFormattings = Map SqRef ConditionalFormatting
    forall k a. Map k a
    M.empty
        , _wsDataValidations :: Map SqRef DataValidation
    _wsDataValidations = Map SqRef DataValidation
    forall k a. Map k a
    M.empty
        , _wsPivotTables :: [PivotTable]
    _wsPivotTables = []
        , _wsAutoFilter :: Maybe AutoFilter
    _wsAutoFilter = Maybe AutoFilter
    forall a. Maybe a
    Nothing
        , _wsTables :: [Table]
    _wsTables = []
        , _wsProtection :: Maybe SheetProtection
    _wsProtection = Maybe SheetProtection
    forall a. Maybe a
    Nothing
        , _wsSharedFormulas :: Map SharedFormulaIndex SharedFormulaOptions
    _wsSharedFormulas = Map SharedFormulaIndex SharedFormulaOptions
    forall k a. Map k a
    M.empty
        , _wsState :: SheetState
    _wsState = SheetState
    forall a. Default a => a
    def
        }

    -- | Raw worksheet styles, for structured implementation see 'StyleSheet'
    -- and functions in "Codec.Xlsx.Types.StyleSheet"
    newtype Styles = Styles {Styles -> ByteString
    unStyles :: L.ByteString}
                deriving (Styles -> Styles -> Bool
    (Styles -> Styles -> Bool)
    -> (Styles -> Styles -> Bool) -> Eq Styles
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: Styles -> Styles -> Bool
    == :: Styles -> Styles -> Bool
    $c/= :: Styles -> Styles -> Bool
    /= :: Styles -> Styles -> Bool
    Eq, Int -> Styles -> ShowS
    [Styles] -> ShowS
    Styles -> String
    (Int -> Styles -> ShowS)
    -> (Styles -> String) -> ([Styles] -> ShowS) -> Show Styles
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> Styles -> ShowS
    showsPrec :: Int -> Styles -> ShowS
    $cshow :: Styles -> String
    show :: Styles -> String
    $cshowList :: [Styles] -> ShowS
    showList :: [Styles] -> ShowS
    Show, (forall x. Styles -> Rep Styles x)
    -> (forall x. Rep Styles x -> Styles) -> Generic Styles
    forall x. Rep Styles x -> Styles
    forall x. Styles -> Rep Styles x
    forall a.
    (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
    $cfrom :: forall x. Styles -> Rep Styles x
    from :: forall x. Styles -> Rep Styles x
    $cto :: forall x. Rep Styles x -> Styles
    to :: forall x. Rep Styles x -> Styles
    Generic)
    instance NFData Styles

    -- | Structured representation of Xlsx file (currently a subset of its contents)
    data Xlsx = Xlsx
      { Xlsx -> [(Text, Worksheet)]
    _xlSheets :: [(Text, Worksheet)]
      , Xlsx -> Styles
    _xlStyles :: Styles
      , Xlsx -> DefinedNames
    _xlDefinedNames :: DefinedNames
      , Xlsx -> Map Text Variant
    _xlCustomProperties :: Map Text Variant
      , Xlsx -> DateBase
    _xlDateBase :: DateBase
      -- ^ date base to use when converting serial value (i.e. 'CellDouble d')
      -- into date-time. Default value is 'DateBase1900'
      --
      -- See also 18.17.4.1 "Date Conversion for Serial Date-Times" (p. 2067)
      } deriving (Xlsx -> Xlsx -> Bool
    (Xlsx -> Xlsx -> Bool) -> (Xlsx -> Xlsx -> Bool) -> Eq Xlsx
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: Xlsx -> Xlsx -> Bool
    == :: Xlsx -> Xlsx -> Bool
    $c/= :: Xlsx -> Xlsx -> Bool
    /= :: Xlsx -> Xlsx -> Bool
    Eq, Int -> Xlsx -> ShowS
    [Xlsx] -> ShowS
    Xlsx -> String
    (Int -> Xlsx -> ShowS)
    -> (Xlsx -> String) -> ([Xlsx] -> ShowS) -> Show Xlsx
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> Xlsx -> ShowS
    showsPrec :: Int -> Xlsx -> ShowS
    $cshow :: Xlsx -> String
    show :: Xlsx -> String
    $cshowList :: [Xlsx] -> ShowS
    showList :: [Xlsx] -> ShowS
    Show, (forall x. Xlsx -> Rep Xlsx x)
    -> (forall x. Rep Xlsx x -> Xlsx) -> Generic Xlsx
    forall x. Rep Xlsx x -> Xlsx
    forall x. Xlsx -> Rep Xlsx x
    forall a.
    (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
    $cfrom :: forall x. Xlsx -> Rep Xlsx x
    from :: forall x. Xlsx -> Rep Xlsx x
    $cto :: forall x. Rep Xlsx x -> Xlsx
    to :: forall x. Rep Xlsx x -> Xlsx
    Generic)
    instance NFData Xlsx

    -- | Defined names
    --
    -- Each defined name consists of a name, an optional local sheet ID, and a value.
    --
    -- This element defines the collection of defined names for this workbook.
    -- Defined names are descriptive names to represent cells, ranges of cells,
    -- formulas, or constant values. Defined names can be used to represent a range
    -- on any worksheet.
    --
    -- Excel also defines a number of reserved names with a special interpretation:
    --
    -- * @_xlnm.Print_Area@ specifies the workbook's print area.
    --   Example value: @SheetName!$A:$A,SheetName!$1:$4@
    -- * @_xlnm.Print_Titles@ specifies the row(s) or column(s) to repeat
    --   at the top of each printed page.
    -- * @_xlnm.Sheet_Title@:refers to a sheet title.
    --
    -- and others. See Section 18.2.6, "definedNames (Defined Names)" (p. 1728) of
    -- the spec (second edition).
    --
    -- NOTE: Right now this is only a minimal implementation of defined names.
    newtype DefinedNames = DefinedNames [(Text, Maybe Text, Text)]
      deriving (DefinedNames -> DefinedNames -> Bool
    (DefinedNames -> DefinedNames -> Bool)
    -> (DefinedNames -> DefinedNames -> Bool) -> Eq DefinedNames
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: DefinedNames -> DefinedNames -> Bool
    == :: DefinedNames -> DefinedNames -> Bool
    $c/= :: DefinedNames -> DefinedNames -> Bool
    /= :: DefinedNames -> DefinedNames -> Bool
    Eq, Int -> DefinedNames -> ShowS
    [DefinedNames] -> ShowS
    DefinedNames -> String
    (Int -> DefinedNames -> ShowS)
    -> (DefinedNames -> String)
    -> ([DefinedNames] -> ShowS)
    -> Show DefinedNames
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> DefinedNames -> ShowS
    showsPrec :: Int -> DefinedNames -> ShowS
    $cshow :: DefinedNames -> String
    show :: DefinedNames -> String
    $cshowList :: [DefinedNames] -> ShowS
    showList :: [DefinedNames] -> ShowS
    Show, (forall x. DefinedNames -> Rep DefinedNames x)
    -> (forall x. Rep DefinedNames x -> DefinedNames)
    -> Generic DefinedNames
    forall x. Rep DefinedNames x -> DefinedNames
    forall x. DefinedNames -> Rep DefinedNames x
    forall a.
    (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
    $cfrom :: forall x. DefinedNames -> Rep DefinedNames x
    from :: forall x. DefinedNames -> Rep DefinedNames x
    $cto :: forall x. Rep DefinedNames x -> DefinedNames
    to :: forall x. Rep DefinedNames x -> DefinedNames
    Generic)
    instance NFData DefinedNames

    makeLenses ''Xlsx

    instance Default Xlsx where
        def :: Xlsx
    def = [(Text, Worksheet)]
    -> Styles -> DefinedNames -> Map Text Variant -> DateBase -> Xlsx
    Xlsx [] Styles
    emptyStyles DefinedNames
    forall a. Default a => a
    def Map Text Variant
    forall k a. Map k a
    M.empty DateBase
    DateBase1900

    instance Default DefinedNames where
        def :: DefinedNames
    def = [(Text, Maybe Text, Text)] -> DefinedNames
    DefinedNames []

    emptyStyles :: Styles
    emptyStyles :: Styles
    emptyStyles = ByteString -> Styles
    Styles ByteString
    "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><styleSheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\"></styleSheet>"

    -- | Render 'StyleSheet'
    --
    -- This is used to render a structured 'StyleSheet' into a raw XML 'Styles'
    -- document. Actually /replacing/ 'Styles' with 'StyleSheet' would mean we
    -- would need to write a /parser/ for 'StyleSheet' as well (and would moreover
    -- require that we support the full style sheet specification, which is still
    -- quite a bit of work).
    renderStyleSheet :: StyleSheet -> Styles
    renderStyleSheet :: StyleSheet -> Styles
    renderStyleSheet = ByteString -> Styles
    Styles (ByteString -> Styles)
    -> (StyleSheet -> ByteString) -> StyleSheet -> Styles
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . RenderSettings -> Document -> ByteString
    renderLBS RenderSettings
    forall a. Default a => a
    def (Document -> ByteString)
    -> (StyleSheet -> Document) -> StyleSheet -> ByteString
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . StyleSheet -> Document
    forall a. ToDocument a => a -> Document
    toDocument

    -- | Parse 'StyleSheet'
    --
    -- This is used to parse raw 'Styles' into structured 'StyleSheet'
    -- currently not all of the style sheet specification is supported
    -- so parser (and the data model) is to be completed
    parseStyleSheet :: Styles -> Either SomeException StyleSheet
    parseStyleSheet :: Styles -> Either SomeException StyleSheet
    parseStyleSheet (Styles ByteString
    bs) = ParseSettings -> ByteString -> Either SomeException Document
    parseLBS ParseSettings
    forall a. Default a => a
    def ByteString
    bs Either SomeException Document
    -> (Document -> Either SomeException StyleSheet)
    -> Either SomeException StyleSheet
    forall a b.
    Either SomeException a
    -> (a -> Either SomeException b) -> Either SomeException b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= Document -> Either SomeException StyleSheet
    forall {b}. FromCursor b => Document -> Either SomeException b
    parseDoc
      where
        parseDoc :: Document -> Either SomeException b
    parseDoc Document
    doc = case Cursor -> [b]
    forall a. FromCursor a => Cursor -> [a]
    fromCursor (Document -> Cursor
    fromDocument Document
    doc) of
          [b
    stylesheet] -> b -> Either SomeException b
    forall a b. b -> Either a b
    Right b
    stylesheet
          [b]
    _ -> SomeException -> Either SomeException b
    forall a b. a -> Either a b
    Left (SomeException -> Either SomeException b)
    -> (ParseException -> SomeException)
    -> ParseException
    -> Either SomeException b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ParseException -> SomeException
    forall e. Exception e => e -> SomeException
    toException (ParseException -> Either SomeException b)
    -> ParseException -> Either SomeException b
    forall a b. (a -> b) -> a -> b
    $ String -> ParseException
    ParseException String
    "Could not parse style sheets"

    -- | converts cells mapped by (row, column) into rows which contain
    -- row index and cells as pairs of column indices and cell values
    toRows :: CellMap -> [(RowIndex, [(ColumnIndex, Cell)])]
    toRows :: CellMap -> [(RowIndex, [(ColumnIndex, Cell)])]
    toRows CellMap
    cells =
        ([((RowIndex, ColumnIndex), Cell)]
     -> (RowIndex, [(ColumnIndex, Cell)]))
    -> [[((RowIndex, ColumnIndex), Cell)]]
    -> [(RowIndex, [(ColumnIndex, Cell)])]
    forall a b. (a -> b) -> [a] -> [b]
    map [((RowIndex, ColumnIndex), Cell)]
    -> (RowIndex, [(ColumnIndex, Cell)])
    forall {a} {a} {b}. [((a, a), b)] -> (a, [(a, b)])
    extractRow ([[((RowIndex, ColumnIndex), Cell)]]
     -> [(RowIndex, [(ColumnIndex, Cell)])])
    -> [[((RowIndex, ColumnIndex), Cell)]]
    -> [(RowIndex, [(ColumnIndex, Cell)])]
    forall a b. (a -> b) -> a -> b
    $ (((RowIndex, ColumnIndex), Cell)
     -> ((RowIndex, ColumnIndex), Cell) -> Bool)
    -> [((RowIndex, ColumnIndex), Cell)]
    -> [[((RowIndex, ColumnIndex), Cell)]]
    forall a. (a -> a -> Bool) -> [a] -> [[a]]
    groupBy (RowIndex -> RowIndex -> Bool
    forall a. Eq a => a -> a -> Bool
    (==) (RowIndex -> RowIndex -> Bool)
    -> (((RowIndex, ColumnIndex), Cell) -> RowIndex)
    -> ((RowIndex, ColumnIndex), Cell)
    -> ((RowIndex, ColumnIndex), Cell)
    -> Bool
    forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
    `on` ((RowIndex, ColumnIndex) -> RowIndex
    forall a b. (a, b) -> a
    fst ((RowIndex, ColumnIndex) -> RowIndex)
    -> (((RowIndex, ColumnIndex), Cell) -> (RowIndex, ColumnIndex))
    -> ((RowIndex, ColumnIndex), Cell)
    -> RowIndex
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ((RowIndex, ColumnIndex), Cell) -> (RowIndex, ColumnIndex)
    forall a b. (a, b) -> a
    fst)) ([((RowIndex, ColumnIndex), Cell)]
     -> [[((RowIndex, ColumnIndex), Cell)]])
    -> [((RowIndex, ColumnIndex), Cell)]
    -> [[((RowIndex, ColumnIndex), Cell)]]
    forall a b. (a -> b) -> a -> b
    $ CellMap -> [((RowIndex, ColumnIndex), Cell)]
    forall k a. Map k a -> [(k, a)]
    M.toList CellMap
    cells
      where
        extractRow :: [((a, a), b)] -> (a, [(a, b)])
    extractRow row :: [((a, a), b)]
    row@(((a
    x,a
    _),b
    _):[((a, a), b)]
    _) =
            (a
    x, (((a, a), b) -> (a, b)) -> [((a, a), b)] -> [(a, b)]
    forall a b. (a -> b) -> [a] -> [b]
    map (\((a
    _,a
    y),b
    v) -> (a
    y,b
    v)) [((a, a), b)]
    row)
        extractRow [((a, a), b)]
    _ = String -> (a, [(a, b)])
    forall a. HasCallStack => String -> a
    error String
    "invalid CellMap row"

    -- | reverse to 'toRows'
    fromRows :: [(RowIndex, [(ColumnIndex, Cell)])] -> CellMap
    fromRows :: [(RowIndex, [(ColumnIndex, Cell)])] -> CellMap
    fromRows [(RowIndex, [(ColumnIndex, Cell)])]
    rows = [((RowIndex, ColumnIndex), Cell)] -> CellMap
    forall k a. Ord k => [(k, a)] -> Map k a
    M.fromList ([((RowIndex, ColumnIndex), Cell)] -> CellMap)
    -> [((RowIndex, ColumnIndex), Cell)] -> CellMap
    forall a b. (a -> b) -> a -> b
    $ ((RowIndex, [(ColumnIndex, Cell)])
     -> [((RowIndex, ColumnIndex), Cell)])
    -> [(RowIndex, [(ColumnIndex, Cell)])]
    -> [((RowIndex, ColumnIndex), Cell)]
    forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
    concatMap (RowIndex, [(ColumnIndex, Cell)])
    -> [((RowIndex, ColumnIndex), Cell)]
    forall {a} {b} {b}. (a, [(b, b)]) -> [((a, b), b)]
    mapRow [(RowIndex, [(ColumnIndex, Cell)])]
    rows
      where
        mapRow :: (a, [(b, b)]) -> [((a, b), b)]
    mapRow (a
    r, [(b, b)]
    cells) = ((b, b) -> ((a, b), b)) -> [(b, b)] -> [((a, b), b)]
    forall a b. (a -> b) -> [a] -> [b]
    map (\(b
    c, b
    v) -> ((a
    r, b
    c), b
    v)) [(b, b)]
    cells

    instance ToElement ColumnsProperties where
      toElement :: Name -> ColumnsProperties -> Element
    toElement Name
    nm ColumnsProperties {Bool
    Int
    Maybe Double
    Maybe Int
    cpMin :: ColumnsProperties -> Int
    cpMax :: ColumnsProperties -> Int
    cpWidth :: ColumnsProperties -> Maybe Double
    cpStyle :: ColumnsProperties -> Maybe Int
    cpHidden :: ColumnsProperties -> Bool
    cpCollapsed :: ColumnsProperties -> Bool
    cpBestFit :: ColumnsProperties -> Bool
    cpMin :: Int
    cpMax :: Int
    cpWidth :: Maybe Double
    cpStyle :: Maybe Int
    cpHidden :: Bool
    cpCollapsed :: Bool
    cpBestFit :: Bool
    ..} = Name -> [(Name, Text)] -> Element
    leafElement Name
    nm [(Name, Text)]
    attrs
        where
          attrs :: [(Name, Text)]
    attrs =
            [Name
    "min" Name -> Int -> (Name, Text)
    forall a. ToAttrVal a => Name -> a -> (Name, Text)
    .= Int
    cpMin, Name
    "max" Name -> Int -> (Name, Text)
    forall a. ToAttrVal a => Name -> a -> (Name, Text)
    .= Int
    cpMax] [(Name, Text)] -> [(Name, Text)] -> [(Name, Text)]
    forall a. [a] -> [a] -> [a]
    ++
            [Maybe (Name, Text)] -> [(Name, Text)]
    forall a. [Maybe a] -> [a]
    catMaybes
              [ Name
    "style" Name -> Maybe Int -> Maybe (Name, Text)
    forall a. ToAttrVal a => Name -> Maybe a -> Maybe (Name, Text)
    .=? (Int -> Int -> Maybe Int
    forall a. Eq a => a -> a -> Maybe a
    justNonDef Int
    0 (Int -> Maybe Int) -> Maybe Int -> Maybe Int
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
    =<< Maybe Int
    cpStyle)
              , Name
    "width" Name -> Maybe Double -> Maybe (Name, Text)
    forall a. ToAttrVal a => Name -> Maybe a -> Maybe (Name, Text)
    .=? Maybe Double
    cpWidth
              , Name
    "customWidth" Name -> Maybe Bool -> Maybe (Name, Text)
    forall a. ToAttrVal a => Name -> Maybe a -> Maybe (Name, Text)
    .=? Bool -> Maybe Bool
    justTrue (Maybe Double -> Bool
    forall a. Maybe a -> Bool
    isJust Maybe Double
    cpWidth)
              , Name
    "hidden" Name -> Maybe Bool -> Maybe (Name, Text)
    forall a. ToAttrVal a => Name -> Maybe a -> Maybe (Name, Text)
    .=? Bool -> Maybe Bool
    justTrue Bool
    cpHidden
              , Name
    "collapsed" Name -> Maybe Bool -> Maybe (Name, Text)
    forall a. ToAttrVal a => Name -> Maybe a -> Maybe (Name, Text)
    .=? Bool -> Maybe Bool
    justTrue Bool
    cpCollapsed
              , Name
    "bestFit" Name -> Maybe Bool -> Maybe (Name, Text)
    forall a. ToAttrVal a => Name -> Maybe a -> Maybe (Name, Text)
    .=? Bool -> Maybe Bool
    justTrue Bool
    cpBestFit
              ]