Skip to content

Commit f2f90f6

Browse files
committed
wip
1 parent ceda7ba commit f2f90f6

File tree

9 files changed

+104
-134
lines changed

9 files changed

+104
-134
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,16 +244,16 @@ formatWorkbook nfcss initStyle = extract go
244244
return
245245
( name,
246246
def
247-
& wsCells
247+
& #wsCells
248248
.~ M.fromList (concat cs')
249-
& wsMerges
249+
& #wsMerges
250250
.~ merges
251251
)
252252
extract (sheets, st) =
253253
def
254-
& xlSheets
254+
& #xlSheets
255255
.~ sheets
256-
& xlStyles
256+
& #xlStyles
257257
.~ renderStyleSheet (updateStyleSheetFromState initStyle st)
258258

259259
-- | reverse to 'formatted' which allows to get a map of formatted cells

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ upsert k v ((k1, v1) : r) =
6565
-- | lens giving access to a worksheet from 'Xlsx' object
6666
-- by its name
6767
ixSheet :: Text -> Traversal' Xlsx Worksheet
68-
ixSheet s = xlSheets . \f -> fmap unSheetList . ix s f . SheetList
68+
ixSheet s = #xlSheets . \f -> fmap unSheetList . ix s f . SheetList
6969

7070
-- | 'Control.Lens.At' variant of 'ixSheet' lens
7171
--
7272
-- /Note:/ if there is no such sheet in this workbook then new sheet will be
7373
-- added as the last one to the sheet list
7474
atSheet :: Text -> Lens' Xlsx (Maybe Worksheet)
75-
atSheet s = xlSheets . \f -> fmap unSheetList . at s f . SheetList
75+
atSheet s = #xlSheets . \f -> fmap unSheetList . at s f . SheetList
7676

7777
-- | lens giving access to a cell in some worksheet
7878
-- by its position, by default row+column index is used
@@ -82,7 +82,7 @@ ixCell = ixCellRC
8282

8383
-- | lens to access cell in a worksheet
8484
ixCellRC :: (RowIndex, ColumnIndex) -> Traversal' Worksheet Cell
85-
ixCellRC i = wsCells . ix i
85+
ixCellRC i = #wsCells . ix i
8686

8787
-- | lens to access cell in a worksheet using more traditional
8888
-- x+y coordinates
@@ -96,7 +96,7 @@ atCell = atCellRC
9696

9797
-- | lens to read, write or delete cell in a worksheet
9898
atCellRC :: (RowIndex, ColumnIndex) -> Lens' Worksheet (Maybe Cell)
99-
atCellRC i = wsCells . at i
99+
atCellRC i = #wsCells . at i
100100

101101
-- | lens to read, write or delete cell in a worksheet
102102
-- using more traditional x+y or row+column index

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ toXlsxEitherBase parseSheet bs = do
118118
(wfs, names, cacheSources, dateBase) <- readWorkbook ar
119119
sheets <- forM wfs $ \wf -> do
120120
sheet <- parseSheet ar sst contentTypes cacheSources wf
121-
return . (wfName wf,) . (wsState .~ wfState wf) $ sheet
121+
return . (wfName wf,) . (#wsState .~ wfState wf) $ sheet
122122
CustomProperties customPropMap <- getCustomProperties ar
123123
return $ Xlsx sheets (getStyles ar) names customPropMap dateBase
124124

@@ -160,37 +160,37 @@ extractSheetFast ar sst contentTypes caches wf = do
160160
liftEither . collectChildren root $ do
161161
skip "sheetPr"
162162
skip "dimension"
163-
_wsSheetViews <- fmap justNonEmpty . maybeParse "sheetViews" $ \n ->
163+
wsSheetViews <- fmap justNonEmpty . maybeParse "sheetViews" $ \n ->
164164
collectChildren n $ fromChildList "sheetView"
165165
skip "sheetFormatPr"
166-
_wsColumnsProperties <-
166+
wsColumnsProperties <-
167167
fmap (fromMaybe []) . maybeParse "cols" $ \n ->
168168
collectChildren n (fromChildList "col")
169-
(_wsRowPropertiesMap, _wsCells, _wsSharedFormulas) <-
169+
(wsRowPropertiesMap, wsCells, wsSharedFormulas) <-
170170
requireAndParse "sheetData" $ \n -> do
171171
rows <- collectChildren n $ childList "row"
172172
collectRows <$> forM rows parseRow
173173
skip "sheetCalcPr"
174-
_wsProtection <- maybeFromChild "sheetProtection"
174+
wsProtection <- maybeFromChild "sheetProtection"
175175
skip "protectedRanges"
176176
skip "scenarios"
177-
_wsAutoFilter <- maybeFromChild "autoFilter"
177+
wsAutoFilter <- maybeFromChild "autoFilter"
178178
skip "sortState"
179179
skip "dataConsolidate"
180180
skip "customSheetViews"
181-
_wsMerges <- fmap (fromMaybe []) . maybeParse "mergeCells" $ \n -> do
181+
wsMerges <- fmap (fromMaybe []) . maybeParse "mergeCells" $ \n -> do
182182
mCells <- collectChildren n $ childList "mergeCell"
183183
forM mCells $ \mCell -> parseAttributes mCell $ fromAttr "ref"
184-
_wsConditionalFormattings <-
184+
wsConditionalFormattings <-
185185
M.fromList . map unCfPair <$> fromChildList "conditionalFormatting"
186-
_wsDataValidations <-
186+
wsDataValidations <-
187187
fmap (fromMaybe mempty) . maybeParse "dataValidations" $ \n -> do
188188
M.fromList . map unDvPair
189189
<$> collectChildren n (fromChildList "dataValidation")
190190
skip "hyperlinks"
191191
skip "printOptions"
192192
skip "pageMargins"
193-
_wsPageSetup <- maybeFromChild "pageSetup"
193+
wsPageSetup <- maybeFromChild "pageSetup"
194194
skip "headerFooter"
195195
skip "rowBreaks"
196196
skip "colBreaks"
@@ -210,10 +210,10 @@ extractSheetFast ar sst contentTypes caches wf = do
210210
-- all explicitly assigned fields filled below
211211
return
212212
( Worksheet
213-
{ _wsDrawing = Nothing,
214-
_wsPivotTables = [],
215-
_wsTables = [],
216-
_wsState = wfState wf,
213+
{ wsDrawing = Nothing,
214+
wsPivotTables = [],
215+
wsTables = [],
216+
wsState = wfState wf,
217217
..
218218
},
219219
tableIds,
@@ -253,13 +253,13 @@ extractSheetFast ar sst contentTypes caches wf = do
253253

254254
return $
255255
ws
256-
& wsTables
256+
& #wsTables
257257
.~ tables
258-
& wsCells
258+
& #wsCells
259259
%~ mergeComments
260-
& wsDrawing
260+
& #wsDrawing
261261
.~ drawing
262-
& wsPivotTables
262+
& #wsPivotTables
263263
.~ pivotTables
264264
liftEither :: Either Text a -> Parser a
265265
liftEither = left (\t -> InvalidFile filePath t)

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

Lines changed: 35 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -27,36 +27,6 @@ module Codec.Xlsx.Types
2727

2828
-- * Lenses
2929

30-
-- ** Workbook
31-
xlSheets,
32-
xlStyles,
33-
xlDefinedNames,
34-
xlCustomProperties,
35-
xlDateBase,
36-
37-
-- ** Worksheet
38-
wsColumnsProperties,
39-
wsRowPropertiesMap,
40-
wsCells,
41-
wsDrawing,
42-
wsMerges,
43-
wsSheetViews,
44-
wsPageSetup,
45-
wsConditionalFormattings,
46-
wsDataValidations,
47-
wsPivotTables,
48-
wsAutoFilter,
49-
wsTables,
50-
wsProtection,
51-
wsSharedFormulas,
52-
wsState,
53-
54-
-- ** Cells
55-
Cell.cellValue,
56-
Cell.cellStyle,
57-
Cell.cellComment,
58-
Cell.cellFormula,
59-
6030
-- ** Row properties
6131
rowHeightLens,
6232
_CustomHeight,
@@ -285,50 +255,48 @@ instance ToAttrVal SheetState where
285255
-- | Xlsx worksheet
286256
data Worksheet = Worksheet
287257
{ -- | column widths
288-
_wsColumnsProperties :: [ColumnsProperties],
258+
wsColumnsProperties :: [ColumnsProperties],
289259
-- | custom row properties (height, style) map
290-
_wsRowPropertiesMap :: Map RowIndex RowProperties,
260+
wsRowPropertiesMap :: Map RowIndex RowProperties,
291261
-- | data mapped by (row, column) pairs
292-
_wsCells :: CellMap,
262+
wsCells :: CellMap,
293263
-- | SpreadsheetML Drawing
294-
_wsDrawing :: Maybe Drawing,
264+
wsDrawing :: Maybe Drawing,
295265
-- | list of cell merges
296-
_wsMerges :: [Range],
297-
_wsSheetViews :: Maybe [SheetView],
298-
_wsPageSetup :: Maybe PageSetup,
299-
_wsConditionalFormattings :: Map SqRef ConditionalFormatting,
300-
_wsDataValidations :: Map SqRef DataValidation,
301-
_wsPivotTables :: [PivotTable],
302-
_wsAutoFilter :: Maybe AutoFilter,
303-
_wsTables :: [Table],
304-
_wsProtection :: Maybe SheetProtection,
305-
_wsSharedFormulas :: Map SharedFormulaIndex SharedFormulaOptions,
306-
_wsState :: SheetState
266+
wsMerges :: [Range],
267+
wsSheetViews :: Maybe [SheetView],
268+
wsPageSetup :: Maybe PageSetup,
269+
wsConditionalFormattings :: Map SqRef ConditionalFormatting,
270+
wsDataValidations :: Map SqRef DataValidation,
271+
wsPivotTables :: [PivotTable],
272+
wsAutoFilter :: Maybe AutoFilter,
273+
wsTables :: [Table],
274+
wsProtection :: Maybe SheetProtection,
275+
wsSharedFormulas :: Map SharedFormulaIndex SharedFormulaOptions,
276+
wsState :: SheetState
307277
}
308278
deriving (Eq, Show, Generic)
309279

310280
instance NFData Worksheet
311281

312-
makeLenses ''Worksheet
313-
314282
instance Default Worksheet where
315283
def =
316284
Worksheet
317-
{ _wsColumnsProperties = [],
318-
_wsRowPropertiesMap = M.empty,
319-
_wsCells = M.empty,
320-
_wsDrawing = Nothing,
321-
_wsMerges = [],
322-
_wsSheetViews = Nothing,
323-
_wsPageSetup = Nothing,
324-
_wsConditionalFormattings = M.empty,
325-
_wsDataValidations = M.empty,
326-
_wsPivotTables = [],
327-
_wsAutoFilter = Nothing,
328-
_wsTables = [],
329-
_wsProtection = Nothing,
330-
_wsSharedFormulas = M.empty,
331-
_wsState = def
285+
{ wsColumnsProperties = [],
286+
wsRowPropertiesMap = M.empty,
287+
wsCells = M.empty,
288+
wsDrawing = Nothing,
289+
wsMerges = [],
290+
wsSheetViews = Nothing,
291+
wsPageSetup = Nothing,
292+
wsConditionalFormattings = M.empty,
293+
wsDataValidations = M.empty,
294+
wsPivotTables = [],
295+
wsAutoFilter = Nothing,
296+
wsTables = [],
297+
wsProtection = Nothing,
298+
wsSharedFormulas = M.empty,
299+
wsState = def
332300
}
333301

334302
-- | Raw worksheet styles, for structured implementation see 'StyleSheet'
@@ -340,15 +308,15 @@ instance NFData Styles
340308

341309
-- | Structured representation of Xlsx file (currently a subset of its contents)
342310
data Xlsx = Xlsx
343-
{ _xlSheets :: [(Text, Worksheet)],
344-
_xlStyles :: Styles,
345-
_xlDefinedNames :: DefinedNames,
346-
_xlCustomProperties :: Map Text Variant,
311+
{ xlSheets :: [(Text, Worksheet)],
312+
xlStyles :: Styles,
313+
xlDefinedNames :: DefinedNames,
314+
xlCustomProperties :: Map Text Variant,
347315
-- | date base to use when converting serial value (i.e. 'CellDouble d')
348316
-- into date-time. Default value is 'DateBase1900'
349317
--
350318
-- See also 18.17.4.1 "Date Conversion for Serial Date-Times" (p. 2067)
351-
_xlDateBase :: DateBase
319+
xlDateBase :: DateBase
352320
}
353321
deriving (Eq, Show, Generic)
354322

@@ -380,8 +348,6 @@ newtype DefinedNames = DefinedNames [(Text, Maybe Text, Text)]
380348

381349
instance NFData DefinedNames
382350

383-
makeLenses ''Xlsx
384-
385351
instance Default Xlsx where
386352
def = Xlsx [] emptyStyles def M.empty DateBase1900
387353

pub/xlsx/src/Codec/Xlsx/Types/Internal/SharedStringTable.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ sstConstruct =
9898
SharedStringTable . V.fromList . uniq . concatMap goSheet
9999
where
100100
goSheet :: Worksheet -> [XlsxText]
101-
goSheet = mapMaybe (cellValue >=> sstEntry) . Map.elems . _wsCells
101+
goSheet = mapMaybe (cellValue >=> sstEntry) . Map.elems . wsCells
102102

103103
sstEntry :: CellValue -> Maybe XlsxText
104104
sstEntry (CellText text) = Just $ XlsxText text

0 commit comments

Comments
 (0)