Skip to content

Commit 09ab918

Browse files
committed
eliminating xlsx th wip
1 parent a924f8e commit 09ab918

File tree

5 files changed

+474
-602
lines changed

5 files changed

+474
-602
lines changed

pub/xlsx/src/Codec/Xlsx/Formatted.hs

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ data FormattingState = FormattingState
6060
stateFromStyleSheet :: StyleSheet -> FormattingState
6161
stateFromStyleSheet StyleSheet {..} =
6262
FormattingState
63-
{ formattingBorders = fromValueList _styleSheetBorders,
64-
formattingCellXfs = fromValueList _styleSheetCellXfs,
65-
formattingFills = fromValueList _styleSheetFills,
66-
formattingFonts = fromValueList _styleSheetFonts,
67-
formattingNumFmts = M.fromList . map swap $ M.toList _styleSheetNumFmts,
63+
{ formattingBorders = fromValueList styleSheetBorders,
64+
formattingCellXfs = fromValueList styleSheetCellXfs,
65+
formattingFills = fromValueList styleSheetFills,
66+
formattingFonts = fromValueList styleSheetFonts,
67+
formattingNumFmts = M.fromList . map swap $ M.toList styleSheetNumFmts,
6868
formattingMerges = []
6969
}
7070

@@ -77,11 +77,11 @@ toValueList = map snd . sortBy (comparing fst) . map swap . M.toList
7777
updateStyleSheetFromState :: StyleSheet -> FormattingState -> StyleSheet
7878
updateStyleSheetFromState sSheet FormattingState {..} =
7979
sSheet
80-
{ _styleSheetBorders = toValueList formattingBorders,
81-
_styleSheetCellXfs = toValueList formattingCellXfs,
82-
_styleSheetFills = toValueList formattingFills,
83-
_styleSheetFonts = toValueList formattingFonts,
84-
_styleSheetNumFmts = M.fromList . map swap $ M.toList formattingNumFmts
80+
{ styleSheetBorders = toValueList formattingBorders,
81+
styleSheetCellXfs = toValueList formattingCellXfs,
82+
styleSheetFills = toValueList formattingFills,
83+
styleSheetFonts = toValueList formattingFonts,
84+
styleSheetNumFmts = M.fromList . map swap $ M.toList formattingNumFmts
8585
}
8686

8787
getId ::
@@ -123,8 +123,8 @@ data FormattedCondFmt = FormattedCondFmt
123123
--
124124
-- TODOs:
125125
--
126-
-- * Add a number format ('_cellXfApplyNumberFormat', '_cellXfNumFmtId')
127-
-- * Add references to the named style sheets ('_cellXfId')
126+
-- * Add a number format ('cellXfApplyNumberFormat', 'cellXfNumFmtId')
127+
-- * Add references to the named style sheets ('cellXfId')
128128
data Format = Format
129129
{ formatAlignment :: Maybe Alignment,
130130
formatBorder :: Maybe Border,
@@ -201,7 +201,7 @@ data Formatted = Formatted
201201
-- This has a number of causes:
202202
--
203203
-- * The 'Cell' datatype wants an 'Int' for the style, which is supposed to
204-
-- point into the '_styleSheetCellXfs' part of a stylesheet. However, this can
204+
-- point into the 'styleSheetCellXfs' part of a stylesheet. However, this can
205205
-- be difficult to work with, as it requires manual tracking of cell style
206206
-- IDs, which in turns requires manual tracking of font IDs, border IDs, etc.
207207
-- * Row-span and column-span properties are set on the worksheet as a whole
@@ -272,33 +272,33 @@ toFormattedCells m merges StyleSheet {..} = applyMerges $ M.map toFormattedCell
272272
}
273273
formatFromStyle cellXf =
274274
Format
275-
{ formatAlignment = applied _cellXfApplyAlignment _cellXfAlignment cellXf,
275+
{ formatAlignment = applied cellXfApplyAlignment cellXfAlignment cellXf,
276276
formatBorder =
277277
flip M.lookup borders
278-
=<< applied _cellXfApplyBorder _cellXfBorderId cellXf,
278+
=<< applied cellXfApplyBorder cellXfBorderId cellXf,
279279
formatFill =
280280
flip M.lookup fills
281-
=<< applied _cellXfApplyFill _cellXfFillId cellXf,
281+
=<< applied cellXfApplyFill cellXfFillId cellXf,
282282
formatFont =
283283
flip M.lookup fonts
284-
=<< applied _cellXfApplyFont _cellXfFontId cellXf,
284+
=<< applied cellXfApplyFont cellXfFontId cellXf,
285285
formatNumberFormat =
286286
lookupNumFmt
287-
=<< applied _cellXfApplyNumberFormat _cellXfNumFmtId cellXf,
288-
formatProtection = _cellXfProtection cellXf,
289-
formatPivotButton = _cellXfPivotButton cellXf,
290-
formatQuotePrefix = _cellXfQuotePrefix cellXf
287+
=<< applied cellXfApplyNumberFormat cellXfNumFmtId cellXf,
288+
formatProtection = cellXfProtection cellXf,
289+
formatPivotButton = cellXfPivotButton cellXf,
290+
formatQuotePrefix = cellXfQuotePrefix cellXf
291291
}
292292
idMapped :: [a] -> Map Int a
293293
idMapped = M.fromList . zip [0 ..]
294-
cellXfs = idMapped _styleSheetCellXfs
295-
borders = idMapped _styleSheetBorders
296-
fills = idMapped _styleSheetFills
297-
fonts = idMapped _styleSheetFonts
294+
cellXfs = idMapped styleSheetCellXfs
295+
borders = idMapped styleSheetBorders
296+
fills = idMapped styleSheetFills
297+
fonts = idMapped styleSheetFonts
298298
lookupNumFmt fId =
299299
asum
300300
[ StdNumberFormat <$> idToStdNumberFormat fId,
301-
UserNumberFormat <$> M.lookup fId _styleSheetNumFmts
301+
UserNumberFormat <$> M.lookup fId styleSheetNumFmts
302302
]
303303
applied :: (CellXf -> Maybe Bool) -> (CellXf -> Maybe a) -> CellXf -> Maybe a
304304
applied applyProp prop cXf = do
@@ -331,12 +331,12 @@ conditionallyFormatted ::
331331
Map CellRef [FormattedCondFmt] -> StyleSheet -> CondFormatted
332332
conditionallyFormatted cfs styleSheet =
333333
CondFormatted
334-
{ condformattedStyleSheet = styleSheet & styleSheetDxfs .~ finalDxfs,
334+
{ condformattedStyleSheet = styleSheet & #styleSheetDxfs .~ finalDxfs,
335335
condformattedFormattings = fmts
336336
}
337337
where
338338
(cellFmts, dxf2id) = runState (mapM (mapM mapDxf) cfs) dxf2id0
339-
dxf2id0 = fromValueList (styleSheet ^. styleSheetDxfs)
339+
dxf2id0 = fromValueList (styleSheet ^. #styleSheetDxfs)
340340
fmts =
341341
M.fromList
342342
. map mergeSqRef
@@ -408,14 +408,14 @@ cellBlock (row, col) cell@FormattedCell {..} = (block, merge)
408408
borderAt :: (RowIndex, ColumnIndex) -> Border
409409
borderAt (row', col') =
410410
def
411-
& borderTop
412-
.~ do guard (row' == topRow); _borderTop =<< border
413-
& borderBottom
414-
.~ do guard (row' == bottomRow); _borderBottom =<< border
415-
& borderLeft
416-
.~ do guard (col' == leftCol); _borderLeft =<< border
417-
& borderRight
418-
.~ do guard (col' == rightCol); _borderRight =<< border
411+
& #borderTop
412+
.~ do guard (row' == topRow); borderTop =<< border
413+
& #borderBottom
414+
.~ do guard (row' == bottomRow); borderBottom =<< border
415+
& #borderLeft
416+
.~ do guard (col' == leftCol); borderLeft =<< border
417+
& #borderRight
418+
.~ do guard (col' == rightCol); borderRight =<< border
419419

420420
topRow, bottomRow :: RowIndex
421421
leftCol, rightCol :: ColumnIndex
@@ -441,21 +441,21 @@ constructCellXf FormattedCell {formattedFormat = Format {..}} = do
441441
mNumFmtId <- getFmtId #formattingNumFmts `mapM` formatNumberFormat
442442
let xf =
443443
CellXf
444-
{ _cellXfApplyAlignment = apply formatAlignment,
445-
_cellXfApplyBorder = apply mBorderId,
446-
_cellXfApplyFill = apply mFillId,
447-
_cellXfApplyFont = apply mFontId,
448-
_cellXfApplyNumberFormat = apply formatNumberFormat,
449-
_cellXfApplyProtection = apply formatProtection,
450-
_cellXfBorderId = mBorderId,
451-
_cellXfFillId = mFillId,
452-
_cellXfFontId = mFontId,
453-
_cellXfNumFmtId = mNumFmtId,
454-
_cellXfPivotButton = formatPivotButton,
455-
_cellXfQuotePrefix = formatQuotePrefix,
456-
_cellXfId = Nothing, -- TODO
457-
_cellXfAlignment = formatAlignment,
458-
_cellXfProtection = formatProtection
444+
{ cellXfApplyAlignment = apply formatAlignment,
445+
cellXfApplyBorder = apply mBorderId,
446+
cellXfApplyFill = apply mFillId,
447+
cellXfApplyFont = apply mFontId,
448+
cellXfApplyNumberFormat = apply formatNumberFormat,
449+
cellXfApplyProtection = apply formatProtection,
450+
cellXfBorderId = mBorderId,
451+
cellXfFillId = mFillId,
452+
cellXfFontId = mFontId,
453+
cellXfNumFmtId = mNumFmtId,
454+
cellXfPivotButton = formatPivotButton,
455+
cellXfQuotePrefix = formatQuotePrefix,
456+
cellXfId = Nothing, -- TODO
457+
cellXfAlignment = formatAlignment,
458+
cellXfProtection = formatProtection
459459
}
460460
return $ if xf == def then Nothing else Just xf
461461
where

pub/xlsx/src/Codec/Xlsx/Types/DataValidation.hs

Lines changed: 41 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,10 @@
33
{-# LANGUAGE MultiParamTypeClasses #-}
44
{-# LANGUAGE OverloadedStrings #-}
55
{-# LANGUAGE RecordWildCards #-}
6-
{-# LANGUAGE TemplateHaskell #-}
76

87
module Codec.Xlsx.Types.DataValidation
98
( ValidationExpression (..),
109
ValidationType (..),
11-
dvAllowBlank,
12-
dvError,
13-
dvErrorStyle,
14-
dvErrorTitle,
15-
dvPrompt,
16-
dvPromptTitle,
17-
dvShowDropDown,
18-
dvShowErrorMessage,
19-
dvShowInputMessage,
20-
dvValidationType,
2110
ErrorStyle (..),
2211
DataValidation (..),
2312
ListOrRangeExpression (..),
@@ -114,23 +103,21 @@ instance NFData ErrorStyle
114103

115104
-- See 18.3.1.32 "dataValidation (Data Validation)" (p. 1614/1624)
116105
data DataValidation = DataValidation
117-
{ _dvAllowBlank :: Bool,
118-
_dvError :: Maybe Text,
119-
_dvErrorStyle :: ErrorStyle,
120-
_dvErrorTitle :: Maybe Text,
121-
_dvPrompt :: Maybe Text,
122-
_dvPromptTitle :: Maybe Text,
123-
_dvShowDropDown :: Bool,
124-
_dvShowErrorMessage :: Bool,
125-
_dvShowInputMessage :: Bool,
126-
_dvValidationType :: ValidationType
106+
{ dvAllowBlank :: Bool,
107+
dvError :: Maybe Text,
108+
dvErrorStyle :: ErrorStyle,
109+
dvErrorTitle :: Maybe Text,
110+
dvPrompt :: Maybe Text,
111+
dvPromptTitle :: Maybe Text,
112+
dvShowDropDown :: Bool,
113+
dvShowErrorMessage :: Bool,
114+
dvShowInputMessage :: Bool,
115+
dvValidationType :: ValidationType
127116
}
128117
deriving (Eq, Show, Generic)
129118

130119
instance NFData DataValidation
131120

132-
makeLenses ''DataValidation
133-
134121
instance Default DataValidation where
135122
def =
136123
DataValidation
@@ -163,35 +150,35 @@ instance FromAttrBs ErrorStyle where
163150

164151
instance FromCursor DataValidation where
165152
fromCursor cur = do
166-
_dvAllowBlank <- fromAttributeDef "allowBlank" False cur
167-
_dvError <- maybeAttribute "error" cur
168-
_dvErrorStyle <- fromAttributeDef "errorStyle" ErrorStyleStop cur
169-
_dvErrorTitle <- maybeAttribute "errorTitle" cur
153+
dvAllowBlank <- fromAttributeDef "allowBlank" False cur
154+
dvError <- maybeAttribute "error" cur
155+
dvErrorStyle <- fromAttributeDef "errorStyle" ErrorStyleStop cur
156+
dvErrorTitle <- maybeAttribute "errorTitle" cur
170157
mop <- fromAttributeDef "operator" "between" cur
171-
_dvPrompt <- maybeAttribute "prompt" cur
172-
_dvPromptTitle <- maybeAttribute "promptTitle" cur
173-
_dvShowDropDown <- fromAttributeDef "showDropDown" False cur
174-
_dvShowErrorMessage <- fromAttributeDef "showErrorMessage" False cur
175-
_dvShowInputMessage <- fromAttributeDef "showInputMessage" False cur
158+
dvPrompt <- maybeAttribute "prompt" cur
159+
dvPromptTitle <- maybeAttribute "promptTitle" cur
160+
dvShowDropDown <- fromAttributeDef "showDropDown" False cur
161+
dvShowErrorMessage <- fromAttributeDef "showErrorMessage" False cur
162+
dvShowInputMessage <- fromAttributeDef "showInputMessage" False cur
176163
mtype <- fromAttributeDef "type" "none" cur
177-
_dvValidationType <- readValidationType mop mtype cur
164+
dvValidationType <- readValidationType mop mtype cur
178165
return DataValidation {..}
179166

180167
instance FromXenoNode DataValidation where
181168
fromXenoNode root = do
182169
(op, atype, genDV) <- parseAttributes root $ do
183-
_dvAllowBlank <- fromAttrDef "allowBlank" False
184-
_dvError <- maybeAttr "error"
185-
_dvErrorStyle <- fromAttrDef "errorStyle" ErrorStyleStop
186-
_dvErrorTitle <- maybeAttr "errorTitle"
187-
_dvPrompt <- maybeAttr "prompt"
188-
_dvPromptTitle <- maybeAttr "promptTitle"
189-
_dvShowDropDown <- fromAttrDef "showDropDown" False
190-
_dvShowErrorMessage <- fromAttrDef "showErrorMessage" False
191-
_dvShowInputMessage <- fromAttrDef "showInputMessage" False
170+
dvAllowBlank <- fromAttrDef "allowBlank" False
171+
dvError <- maybeAttr "error"
172+
dvErrorStyle <- fromAttrDef "errorStyle" ErrorStyleStop
173+
dvErrorTitle <- maybeAttr "errorTitle"
174+
dvPrompt <- maybeAttr "prompt"
175+
dvPromptTitle <- maybeAttr "promptTitle"
176+
dvShowDropDown <- fromAttrDef "showDropDown" False
177+
dvShowErrorMessage <- fromAttrDef "showErrorMessage" False
178+
dvShowInputMessage <- fromAttrDef "showInputMessage" False
192179
op <- fromAttrDef "operator" "between"
193180
typ <- fromAttrDef "type" "none"
194-
return (op, typ, \_dvValidationType -> DataValidation {..})
181+
return (op, typ, \dvValidationType -> DataValidation {..})
195182
valType <- parseValidationType op atype
196183
return $ genDV valType
197184
where
@@ -333,17 +320,17 @@ instance ToElement DataValidation where
333320
{ elementName = nm,
334321
elementAttributes =
335322
M.fromList . catMaybes $
336-
[ Just $ "allowBlank" .= _dvAllowBlank,
337-
"error" .=? _dvError,
338-
Just $ "errorStyle" .= _dvErrorStyle,
339-
"errorTitle" .=? _dvErrorTitle,
323+
[ Just $ "allowBlank" .= dvAllowBlank,
324+
"error" .=? dvError,
325+
Just $ "errorStyle" .= dvErrorStyle,
326+
"errorTitle" .=? dvErrorTitle,
340327
"operator" .=? op,
341-
"prompt" .=? _dvPrompt,
342-
"promptTitle" .=? _dvPromptTitle,
343-
Just $ "showDropDown" .= _dvShowDropDown,
344-
Just $ "showErrorMessage" .= _dvShowErrorMessage,
345-
Just $ "showInputMessage" .= _dvShowInputMessage,
346-
Just $ "type" .= _dvValidationType
328+
"prompt" .=? dvPrompt,
329+
"promptTitle" .=? dvPromptTitle,
330+
Just $ "showDropDown" .= dvShowDropDown,
331+
Just $ "showErrorMessage" .= dvShowErrorMessage,
332+
Just $ "showInputMessage" .= dvShowInputMessage,
333+
Just $ "type" .= dvValidationType
347334
],
348335
elementNodes =
349336
catMaybes
@@ -356,7 +343,7 @@ instance ToElement DataValidation where
356343

357344
op :: Maybe Text
358345
f1, f2 :: Maybe Formula
359-
(op, f1, f2) = case _dvValidationType of
346+
(op, f1, f2) = case dvValidationType of
360347
ValidationTypeNone -> (Nothing, Nothing, Nothing)
361348
ValidationTypeCustom f -> (Nothing, Just f, Nothing)
362349
ValidationTypeDate f -> opExp $ viewValidationExpression f

0 commit comments

Comments
 (0)