module Codec.Xlsx.Types.PageSetup (
PageSetup(..)
, CellComments(..)
, PrintErrors(..)
, Orientation(..)
, PageOrder(..)
, PaperSize(..)
, pageSetupBlackAndWhite
, pageSetupCellComments
, pageSetupCopies
, pageSetupDraft
, pageSetupErrors
, pageSetupFirstPageNumber
, pageSetupFitToHeight
, pageSetupFitToWidth
, pageSetupHorizontalDpi
, pageSetupId
, pageSetupOrientation
, pageSetupPageOrder
, pageSetupPaperHeight
, pageSetupPaperSize
, pageSetupPaperWidth
, pageSetupScale
, pageSetupUseFirstPageNumber
, pageSetupUsePrinterDefaults
, pageSetupVerticalDpi
) where
import Control.Lens (makeLenses)
import Control.DeepSeq (NFData)
import Data.Default
import qualified Data.Map as Map
import Data.Maybe (catMaybes)
import Data.Text (Text)
import GHC.Generics (Generic)
import Text.XML
import Codec.Xlsx.Writer.Internal
import Codec.Xlsx.Parser.Internal
data PageSetup = PageSetup {
_pageSetupBlackAndWhite :: Maybe Bool
, _pageSetupCellComments :: Maybe CellComments
, _pageSetupCopies :: Maybe Int
, _pageSetupDraft :: Maybe Bool
, _pageSetupErrors :: Maybe PrintErrors
, _pageSetupFirstPageNumber :: Maybe Int
, _pageSetupFitToHeight :: Maybe Int
, _pageSetupFitToWidth :: Maybe Int
, _pageSetupHorizontalDpi :: Maybe Int
, _pageSetupId :: Maybe Text
, _pageSetupOrientation :: Maybe Orientation
, _pageSetupPageOrder :: Maybe PageOrder
, _pageSetupPaperHeight :: Maybe Text
, _pageSetupPaperSize :: Maybe PaperSize
, _pageSetupPaperWidth :: Maybe Text
, _pageSetupScale :: Maybe Int
, _pageSetupUseFirstPageNumber :: Maybe Bool
, _pageSetupUsePrinterDefaults :: Maybe Bool
, _pageSetupVerticalDpi :: Maybe Int
}
deriving (Eq, Ord, Show, Generic)
instance NFData PageSetup
data CellComments =
CellCommentsAsDisplayed
| CellCommentsAtEnd
| CellCommentsNone
deriving (Eq, Ord, Show, Generic)
instance NFData CellComments
data PrintErrors =
PrintErrorsBlank
| PrintErrorsDash
| PrintErrorsDisplayed
| PrintErrorsNA
deriving (Eq, Ord, Show, Generic)
instance NFData PrintErrors
data Orientation =
OrientationDefault
| OrientationLandscape
| OrientationPortrait
deriving (Eq, Ord, Show, Generic)
instance NFData Orientation
data PageOrder =
PageOrderDownThenOver
| PageOrderOverThenDown
deriving (Eq, Ord, Show, Generic)
instance NFData PageOrder
data PaperSize =
PaperA2
| PaperA3
| PaperA3Extra
| PaperA3ExtraTransverse
| PaperA3Transverse
| PaperA4
| PaperA4Extra
| PaperA4Plus
| PaperA4Small
| PaperA4Transverse
| PaperA5
| PaperA5Extra
| PaperA5Transverse
| PaperB4
| PaperB5
| PaperC
| PaperD
| PaperE
| PaperExecutive
| PaperFanfoldGermanLegal
| PaperFanfoldGermanStandard
| PaperFanfoldUsStandard
| PaperFolio
| PaperIsoB4
| PaperIsoB5Extra
| PaperJapaneseDoublePostcard
| PaperJisB5Transverse
| PaperLedger
| PaperLegal
| PaperLegalExtra
| PaperLetter
| PaperLetterExtra
| PaperLetterExtraTransverse
| PaperLetterPlus
| PaperLetterSmall
| PaperLetterTransverse
| PaperNote
| PaperQuarto
| PaperStandard9_11
| PaperStandard10_11
| PaperStandard10_14
| PaperStandard11_17
| PaperStandard15_11
| PaperStatement
| PaperSuperA
| PaperSuperB
| PaperTabloid
| PaperTabloidExtra
| Envelope6_3_4
| Envelope9
| Envelope10
| Envelope11
| Envelope12
| Envelope14
| EnvelopeB4
| EnvelopeB5
| EnvelopeB6
| EnvelopeC3
| EnvelopeC4
| EnvelopeC5
| EnvelopeC6
| EnvelopeC65
| EnvelopeDL
| EnvelopeInvite
| EnvelopeItaly
| EnvelopeMonarch
deriving (Eq, Ord, Show, Generic)
instance NFData PaperSize
instance Default PageSetup where
def = PageSetup {
_pageSetupBlackAndWhite = Nothing
, _pageSetupCellComments = Nothing
, _pageSetupCopies = Nothing
, _pageSetupDraft = Nothing
, _pageSetupErrors = Nothing
, _pageSetupFirstPageNumber = Nothing
, _pageSetupFitToHeight = Nothing
, _pageSetupFitToWidth = Nothing
, _pageSetupHorizontalDpi = Nothing
, _pageSetupId = Nothing
, _pageSetupOrientation = Nothing
, _pageSetupPageOrder = Nothing
, _pageSetupPaperHeight = Nothing
, _pageSetupPaperSize = Nothing
, _pageSetupPaperWidth = Nothing
, _pageSetupScale = Nothing
, _pageSetupUseFirstPageNumber = Nothing
, _pageSetupUsePrinterDefaults = Nothing
, _pageSetupVerticalDpi = Nothing
}
makeLenses ''PageSetup
instance ToElement PageSetup where
toElement nm PageSetup{..} = Element {
elementName = nm
, elementNodes = []
, elementAttributes = Map.fromList . catMaybes $ [
"paperSize" .=? _pageSetupPaperSize
, "paperHeight" .=? _pageSetupPaperHeight
, "paperWidth" .=? _pageSetupPaperWidth
, "scale" .=? _pageSetupScale
, "firstPageNumber" .=? _pageSetupFirstPageNumber
, "fitToWidth" .=? _pageSetupFitToWidth
, "fitToHeight" .=? _pageSetupFitToHeight
, "pageOrder" .=? _pageSetupPageOrder
, "orientation" .=? _pageSetupOrientation
, "usePrinterDefaults" .=? _pageSetupUsePrinterDefaults
, "blackAndWhite" .=? _pageSetupBlackAndWhite
, "draft" .=? _pageSetupDraft
, "cellComments" .=? _pageSetupCellComments
, "useFirstPageNumber" .=? _pageSetupUseFirstPageNumber
, "errors" .=? _pageSetupErrors
, "horizontalDpi" .=? _pageSetupHorizontalDpi
, "verticalDpi" .=? _pageSetupVerticalDpi
, "copies" .=? _pageSetupCopies
, "id" .=? _pageSetupId
]
}
instance ToAttrVal CellComments where
toAttrVal CellCommentsNone = "none"
toAttrVal CellCommentsAsDisplayed = "asDisplayed"
toAttrVal CellCommentsAtEnd = "atEnd"
instance ToAttrVal PrintErrors where
toAttrVal PrintErrorsDisplayed = "displayed"
toAttrVal PrintErrorsBlank = "blank"
toAttrVal PrintErrorsDash = "dash"
toAttrVal PrintErrorsNA = "NA"
instance ToAttrVal Orientation where
toAttrVal OrientationDefault = "default"
toAttrVal OrientationPortrait = "portrait"
toAttrVal OrientationLandscape = "landscape"
instance ToAttrVal PageOrder where
toAttrVal PageOrderDownThenOver = "downThenOver"
toAttrVal PageOrderOverThenDown = "overThenDown"
instance ToAttrVal PaperSize where
toAttrVal PaperLetter = "1"
toAttrVal PaperLetterSmall = "2"
toAttrVal PaperTabloid = "3"
toAttrVal PaperLedger = "4"
toAttrVal PaperLegal = "5"
toAttrVal PaperStatement = "6"
toAttrVal PaperExecutive = "7"
toAttrVal PaperA3 = "8"
toAttrVal PaperA4 = "9"
toAttrVal PaperA4Small = "10"
toAttrVal PaperA5 = "11"
toAttrVal PaperB4 = "12"
toAttrVal PaperB5 = "13"
toAttrVal PaperFolio = "14"
toAttrVal PaperQuarto = "15"
toAttrVal PaperStandard10_14 = "16"
toAttrVal PaperStandard11_17 = "17"
toAttrVal PaperNote = "18"
toAttrVal Envelope9 = "19"
toAttrVal Envelope10 = "20"
toAttrVal Envelope11 = "21"
toAttrVal Envelope12 = "22"
toAttrVal Envelope14 = "23"
toAttrVal PaperC = "24"
toAttrVal PaperD = "25"
toAttrVal PaperE = "26"
toAttrVal EnvelopeDL = "27"
toAttrVal EnvelopeC5 = "28"
toAttrVal EnvelopeC3 = "29"
toAttrVal EnvelopeC4 = "30"
toAttrVal EnvelopeC6 = "31"
toAttrVal EnvelopeC65 = "32"
toAttrVal EnvelopeB4 = "33"
toAttrVal EnvelopeB5 = "34"
toAttrVal EnvelopeB6 = "35"
toAttrVal EnvelopeItaly = "36"
toAttrVal EnvelopeMonarch = "37"
toAttrVal Envelope6_3_4 = "38"
toAttrVal PaperFanfoldUsStandard = "39"
toAttrVal PaperFanfoldGermanStandard = "40"
toAttrVal PaperFanfoldGermanLegal = "41"
toAttrVal PaperIsoB4 = "42"
toAttrVal PaperJapaneseDoublePostcard = "43"
toAttrVal PaperStandard9_11 = "44"
toAttrVal PaperStandard10_11 = "45"
toAttrVal PaperStandard15_11 = "46"
toAttrVal EnvelopeInvite = "47"
toAttrVal PaperLetterExtra = "50"
toAttrVal PaperLegalExtra = "51"
toAttrVal PaperTabloidExtra = "52"
toAttrVal PaperA4Extra = "53"
toAttrVal PaperLetterTransverse = "54"
toAttrVal PaperA4Transverse = "55"
toAttrVal PaperLetterExtraTransverse = "56"
toAttrVal PaperSuperA = "57"
toAttrVal PaperSuperB = "58"
toAttrVal PaperLetterPlus = "59"
toAttrVal PaperA4Plus = "60"
toAttrVal PaperA5Transverse = "61"
toAttrVal PaperJisB5Transverse = "62"
toAttrVal PaperA3Extra = "63"
toAttrVal PaperA5Extra = "64"
toAttrVal PaperIsoB5Extra = "65"
toAttrVal PaperA2 = "66"
toAttrVal PaperA3Transverse = "67"
toAttrVal PaperA3ExtraTransverse = "68"
instance FromCursor PageSetup where
fromCursor cur = do
_pageSetupPaperSize <- maybeAttribute "paperSize" cur
_pageSetupPaperHeight <- maybeAttribute "paperHeight" cur
_pageSetupPaperWidth <- maybeAttribute "paperWidth" cur
_pageSetupScale <- maybeAttribute "scale" cur
_pageSetupFirstPageNumber <- maybeAttribute "firstPageNumber" cur
_pageSetupFitToWidth <- maybeAttribute "fitToWidth" cur
_pageSetupFitToHeight <- maybeAttribute "fitToHeight" cur
_pageSetupPageOrder <- maybeAttribute "pageOrder" cur
_pageSetupOrientation <- maybeAttribute "orientation" cur
_pageSetupUsePrinterDefaults <- maybeAttribute "usePrinterDefaults" cur
_pageSetupBlackAndWhite <- maybeAttribute "blackAndWhite" cur
_pageSetupDraft <- maybeAttribute "draft" cur
_pageSetupCellComments <- maybeAttribute "cellComments" cur
_pageSetupUseFirstPageNumber <- maybeAttribute "useFirstPageNumber" cur
_pageSetupErrors <- maybeAttribute "errors" cur
_pageSetupHorizontalDpi <- maybeAttribute "horizontalDpi" cur
_pageSetupVerticalDpi <- maybeAttribute "verticalDpi" cur
_pageSetupCopies <- maybeAttribute "copies" cur
_pageSetupId <- maybeAttribute "id" cur
return PageSetup{..}
instance FromXenoNode PageSetup where
fromXenoNode root =
parseAttributes root $ do
_pageSetupPaperSize <- maybeAttr "paperSize"
_pageSetupPaperHeight <- maybeAttr "paperHeight"
_pageSetupPaperWidth <- maybeAttr "paperWidth"
_pageSetupScale <- maybeAttr "scale"
_pageSetupFirstPageNumber <- maybeAttr "firstPageNumber"
_pageSetupFitToWidth <- maybeAttr "fitToWidth"
_pageSetupFitToHeight <- maybeAttr "fitToHeight"
_pageSetupPageOrder <- maybeAttr "pageOrder"
_pageSetupOrientation <- maybeAttr "orientation"
_pageSetupUsePrinterDefaults <- maybeAttr "usePrinterDefaults"
_pageSetupBlackAndWhite <- maybeAttr "blackAndWhite"
_pageSetupDraft <- maybeAttr "draft"
_pageSetupCellComments <- maybeAttr "cellComments"
_pageSetupUseFirstPageNumber <- maybeAttr "useFirstPageNumber"
_pageSetupErrors <- maybeAttr "errors"
_pageSetupHorizontalDpi <- maybeAttr "horizontalDpi"
_pageSetupVerticalDpi <- maybeAttr "verticalDpi"
_pageSetupCopies <- maybeAttr "copies"
_pageSetupId <- maybeAttr "id"
return PageSetup {..}
instance FromAttrVal PaperSize where
fromAttrVal "1" = readSuccess PaperLetter
fromAttrVal "2" = readSuccess PaperLetterSmall
fromAttrVal "3" = readSuccess PaperTabloid
fromAttrVal "4" = readSuccess PaperLedger
fromAttrVal "5" = readSuccess PaperLegal
fromAttrVal "6" = readSuccess PaperStatement
fromAttrVal "7" = readSuccess PaperExecutive
fromAttrVal "8" = readSuccess PaperA3
fromAttrVal "9" = readSuccess PaperA4
fromAttrVal "10" = readSuccess PaperA4Small
fromAttrVal "11" = readSuccess PaperA5
fromAttrVal "12" = readSuccess PaperB4
fromAttrVal "13" = readSuccess PaperB5
fromAttrVal "14" = readSuccess PaperFolio
fromAttrVal "15" = readSuccess PaperQuarto
fromAttrVal "16" = readSuccess PaperStandard10_14
fromAttrVal "17" = readSuccess PaperStandard11_17
fromAttrVal "18" = readSuccess PaperNote
fromAttrVal "19" = readSuccess Envelope9
fromAttrVal "20" = readSuccess Envelope10
fromAttrVal "21" = readSuccess Envelope11
fromAttrVal "22" = readSuccess Envelope12
fromAttrVal "23" = readSuccess Envelope14
fromAttrVal "24" = readSuccess PaperC
fromAttrVal "25" = readSuccess PaperD
fromAttrVal "26" = readSuccess PaperE
fromAttrVal "27" = readSuccess EnvelopeDL
fromAttrVal "28" = readSuccess EnvelopeC5
fromAttrVal "29" = readSuccess EnvelopeC3
fromAttrVal "30" = readSuccess EnvelopeC4
fromAttrVal "31" = readSuccess EnvelopeC6
fromAttrVal "32" = readSuccess EnvelopeC65
fromAttrVal "33" = readSuccess EnvelopeB4
fromAttrVal "34" = readSuccess EnvelopeB5
fromAttrVal "35" = readSuccess EnvelopeB6
fromAttrVal "36" = readSuccess EnvelopeItaly
fromAttrVal "37" = readSuccess EnvelopeMonarch
fromAttrVal "38" = readSuccess Envelope6_3_4
fromAttrVal "39" = readSuccess PaperFanfoldUsStandard
fromAttrVal "40" = readSuccess PaperFanfoldGermanStandard
fromAttrVal "41" = readSuccess PaperFanfoldGermanLegal
fromAttrVal "42" = readSuccess PaperIsoB4
fromAttrVal "43" = readSuccess PaperJapaneseDoublePostcard
fromAttrVal "44" = readSuccess PaperStandard9_11
fromAttrVal "45" = readSuccess PaperStandard10_11
fromAttrVal "46" = readSuccess PaperStandard15_11
fromAttrVal "47" = readSuccess EnvelopeInvite
fromAttrVal "50" = readSuccess PaperLetterExtra
fromAttrVal "51" = readSuccess PaperLegalExtra
fromAttrVal "52" = readSuccess PaperTabloidExtra
fromAttrVal "53" = readSuccess PaperA4Extra
fromAttrVal "54" = readSuccess PaperLetterTransverse
fromAttrVal "55" = readSuccess PaperA4Transverse
fromAttrVal "56" = readSuccess PaperLetterExtraTransverse
fromAttrVal "57" = readSuccess PaperSuperA
fromAttrVal "58" = readSuccess PaperSuperB
fromAttrVal "59" = readSuccess PaperLetterPlus
fromAttrVal "60" = readSuccess PaperA4Plus
fromAttrVal "61" = readSuccess PaperA5Transverse
fromAttrVal "62" = readSuccess PaperJisB5Transverse
fromAttrVal "63" = readSuccess PaperA3Extra
fromAttrVal "64" = readSuccess PaperA5Extra
fromAttrVal "65" = readSuccess PaperIsoB5Extra
fromAttrVal "66" = readSuccess PaperA2
fromAttrVal "67" = readSuccess PaperA3Transverse
fromAttrVal "68" = readSuccess PaperA3ExtraTransverse
fromAttrVal t = invalidText "PaperSize" t
instance FromAttrBs PaperSize where
fromAttrBs "1" = return PaperLetter
fromAttrBs "2" = return PaperLetterSmall
fromAttrBs "3" = return PaperTabloid
fromAttrBs "4" = return PaperLedger
fromAttrBs "5" = return PaperLegal
fromAttrBs "6" = return PaperStatement
fromAttrBs "7" = return PaperExecutive
fromAttrBs "8" = return PaperA3
fromAttrBs "9" = return PaperA4
fromAttrBs "10" = return PaperA4Small
fromAttrBs "11" = return PaperA5
fromAttrBs "12" = return PaperB4
fromAttrBs "13" = return PaperB5
fromAttrBs "14" = return PaperFolio
fromAttrBs "15" = return PaperQuarto
fromAttrBs "16" = return PaperStandard10_14
fromAttrBs "17" = return PaperStandard11_17
fromAttrBs "18" = return PaperNote
fromAttrBs "19" = return Envelope9
fromAttrBs "20" = return Envelope10
fromAttrBs "21" = return Envelope11
fromAttrBs "22" = return Envelope12
fromAttrBs "23" = return Envelope14
fromAttrBs "24" = return PaperC
fromAttrBs "25" = return PaperD
fromAttrBs "26" = return PaperE
fromAttrBs "27" = return EnvelopeDL
fromAttrBs "28" = return EnvelopeC5
fromAttrBs "29" = return EnvelopeC3
fromAttrBs "30" = return EnvelopeC4
fromAttrBs "31" = return EnvelopeC6
fromAttrBs "32" = return EnvelopeC65
fromAttrBs "33" = return EnvelopeB4
fromAttrBs "34" = return EnvelopeB5
fromAttrBs "35" = return EnvelopeB6
fromAttrBs "36" = return EnvelopeItaly
fromAttrBs "37" = return EnvelopeMonarch
fromAttrBs "38" = return Envelope6_3_4
fromAttrBs "39" = return PaperFanfoldUsStandard
fromAttrBs "40" = return PaperFanfoldGermanStandard
fromAttrBs "41" = return PaperFanfoldGermanLegal
fromAttrBs "42" = return PaperIsoB4
fromAttrBs "43" = return PaperJapaneseDoublePostcard
fromAttrBs "44" = return PaperStandard9_11
fromAttrBs "45" = return PaperStandard10_11
fromAttrBs "46" = return PaperStandard15_11
fromAttrBs "47" = return EnvelopeInvite
fromAttrBs "50" = return PaperLetterExtra
fromAttrBs "51" = return PaperLegalExtra
fromAttrBs "52" = return PaperTabloidExtra
fromAttrBs "53" = return PaperA4Extra
fromAttrBs "54" = return PaperLetterTransverse
fromAttrBs "55" = return PaperA4Transverse
fromAttrBs "56" = return PaperLetterExtraTransverse
fromAttrBs "57" = return PaperSuperA
fromAttrBs "58" = return PaperSuperB
fromAttrBs "59" = return PaperLetterPlus
fromAttrBs "60" = return PaperA4Plus
fromAttrBs "61" = return PaperA5Transverse
fromAttrBs "62" = return PaperJisB5Transverse
fromAttrBs "63" = return PaperA3Extra
fromAttrBs "64" = return PaperA5Extra
fromAttrBs "65" = return PaperIsoB5Extra
fromAttrBs "66" = return PaperA2
fromAttrBs "67" = return PaperA3Transverse
fromAttrBs "68" = return PaperA3ExtraTransverse
fromAttrBs x = unexpectedAttrBs "PaperSize" x
instance FromAttrVal PageOrder where
fromAttrVal "downThenOver" = readSuccess PageOrderDownThenOver
fromAttrVal "overThenDown" = readSuccess PageOrderOverThenDown
fromAttrVal t = invalidText "PageOrder" t
instance FromAttrBs PageOrder where
fromAttrBs "downThenOver" = return PageOrderDownThenOver
fromAttrBs "overThenDown" = return PageOrderOverThenDown
fromAttrBs x = unexpectedAttrBs "PageOrder" x
instance FromAttrVal CellComments where
fromAttrVal "none" = readSuccess CellCommentsNone
fromAttrVal "asDisplayed" = readSuccess CellCommentsAsDisplayed
fromAttrVal "atEnd" = readSuccess CellCommentsAtEnd
fromAttrVal t = invalidText "CellComments" t
instance FromAttrBs CellComments where
fromAttrBs "none" = return CellCommentsNone
fromAttrBs "asDisplayed" = return CellCommentsAsDisplayed
fromAttrBs "atEnd" = return CellCommentsAtEnd
fromAttrBs x = unexpectedAttrBs "CellComments" x
instance FromAttrVal PrintErrors where
fromAttrVal "displayed" = readSuccess PrintErrorsDisplayed
fromAttrVal "blank" = readSuccess PrintErrorsBlank
fromAttrVal "dash" = readSuccess PrintErrorsDash
fromAttrVal "NA" = readSuccess PrintErrorsNA
fromAttrVal t = invalidText "PrintErrors" t
instance FromAttrBs PrintErrors where
fromAttrBs "displayed" = return PrintErrorsDisplayed
fromAttrBs "blank" = return PrintErrorsBlank
fromAttrBs "dash" = return PrintErrorsDash
fromAttrBs "NA" = return PrintErrorsNA
fromAttrBs x = unexpectedAttrBs "PrintErrors" x
instance FromAttrVal Orientation where
fromAttrVal "default" = readSuccess OrientationDefault
fromAttrVal "portrait" = readSuccess OrientationPortrait
fromAttrVal "landscape" = readSuccess OrientationLandscape
fromAttrVal t = invalidText "Orientation" t
instance FromAttrBs Orientation where
fromAttrBs "default" = return OrientationDefault
fromAttrBs "portrait" = return OrientationPortrait
fromAttrBs "landscape" = return OrientationLandscape
fromAttrBs x = unexpectedAttrBs "Orientation" x