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 Data.Default
import Data.Maybe (catMaybes)
import Data.Text (Text)
import Text.XML
import qualified Data.Map as Map
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 (Show, Eq, Ord)
data CellComments =
CellCommentsAsDisplayed
| CellCommentsAtEnd
| CellCommentsNone
deriving (Show, Eq, Ord)
data PrintErrors =
PrintErrorsBlank
| PrintErrorsDash
| PrintErrorsDisplayed
| PrintErrorsNA
deriving (Show, Eq, Ord)
data Orientation =
OrientationDefault
| OrientationLandscape
| OrientationPortrait
deriving (Show, Eq, Ord)
data PageOrder =
PageOrderDownThenOver
| PageOrderOverThenDown
deriving (Show, Eq, Ord)
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 (Show, Eq, Ord)
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 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 FromAttrVal PageOrder where
fromAttrVal "downThenOver" = readSuccess PageOrderDownThenOver
fromAttrVal "overThenDown" = readSuccess PageOrderOverThenDown
fromAttrVal t = invalidText "PageOrder" t
instance FromAttrVal CellComments where
fromAttrVal "none" = readSuccess CellCommentsNone
fromAttrVal "asDisplayed" = readSuccess CellCommentsAsDisplayed
fromAttrVal "atEnd" = readSuccess CellCommentsAtEnd
fromAttrVal t = invalidText "CellComments" t
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 FromAttrVal Orientation where
fromAttrVal "default" = readSuccess OrientationDefault
fromAttrVal "portrait" = readSuccess OrientationPortrait
fromAttrVal "landscape" = readSuccess OrientationLandscape
fromAttrVal t = invalidText "Orientation" t