xlsx 0.1.1.1 → 0.1.2
raw patch · 4 files changed
+62/−31 lines, 4 files
Files
- changelog +2/−0
- src/Codec/Xlsx/Lens.hs +55/−29
- src/Codec/Xlsx/Types.hs +4/−1
- xlsx.cabal +1/−1
changelog view
@@ -1,3 +1,5 @@+0.1.2+ * added lenses to access cells both using RC and XY style coordinates, RC is used by default 0.1.1.1 * fixed use of internal function for parsing shared strings, previous change was unused in practice 0.1.1
src/Codec/Xlsx/Lens.hs view
@@ -1,47 +1,73 @@+-- | lenses to access sheets, cells and values of 'Xlsx'+{-# LANGUAGE RankNTypes #-} module Codec.Xlsx.Lens ( ixSheet , atSheet , ixCell+ , ixCellRC+ , ixCellXY , atCell+ , atCellRC+ , atCellXY , cellValueAt+ , cellValueAtRC+ , cellValueAtXY ) where import Codec.Xlsx.Types-import Control.Applicative import Control.Lens import Data.Text+import Data.Tuple (swap) -ixSheet :: Applicative f- => Text- -> (Worksheet -> f Worksheet)- -> Xlsx- -> f Xlsx+-- | lens giving access to a worksheet from 'Xlsx' object+-- by its name+ixSheet :: Text -> Traversal' Xlsx Worksheet ixSheet s = xlSheets . ix s -atSheet :: Functor f- => Text- -> (Maybe Worksheet -> f (Maybe Worksheet))- -> Xlsx- -> f Xlsx+-- | 'Control.Lens.At' variant of 'ixSheet' lens+atSheet :: Text -> Lens' Xlsx (Maybe Worksheet) atSheet s = xlSheets . at s -ixCell :: Applicative f- => (Int, Int)- -> (Cell -> f Cell)- -> Worksheet- -> f Worksheet-ixCell i = wsCells . ix i+-- | lens giving access to a cell in some worksheet+-- by its position, by default row+column index is used+-- so this lens is a synonym of 'ixCellRC'+ixCell :: (Int, Int) -> Traversal' Worksheet Cell+ixCell = ixCellRC -atCell :: Functor f- => (Int, Int)- -> (Maybe Cell -> f (Maybe Cell))- -> Worksheet- -> f Worksheet-atCell i = wsCells . at i+-- | lens to access cell in a worksheet+ixCellRC :: (Int, Int) -> Traversal' Worksheet Cell+ixCellRC i = wsCells . ix i -cellValueAt :: Functor f- => (Int, Int)- -> (Maybe CellValue -> f (Maybe CellValue))- -> Worksheet- -> f Worksheet-cellValueAt i = atCell i . non def . cellValue+-- | lens to access cell in a worksheet using more traditional+-- x+y coordinates+ixCellXY :: (Int, Int) -> Traversal' Worksheet Cell+ixCellXY = ixCellRC . swap++-- | accessor that can read, write or delete cell in a worksheet+-- synonym of 'atCellRC' so uses row+column index+atCell :: (Int, Int) -> Lens' Worksheet (Maybe Cell)+atCell = atCellRC++-- | lens to read, write or delete cell in a worksheet+atCellRC :: (Int, Int) -> Lens' Worksheet (Maybe Cell)+atCellRC i = wsCells . at i++-- | lens to read, write or delete cell in a worksheet+-- using more traditional x+y or row+column index+atCellXY :: (Int, Int) -> Lens' Worksheet (Maybe Cell)+atCellXY = atCellRC . swap++-- | lens to read, write or delete cell value in a worksheet+-- with row+column coordinates, synonym for 'cellValueRC'+cellValueAt :: (Int, Int) -> Lens' Worksheet (Maybe CellValue)+cellValueAt = cellValueAtRC++-- | lens to read, write or delete cell value in a worksheet+-- using row+column coordinates of that cell+cellValueAtRC :: (Int, Int) -> Lens' Worksheet (Maybe CellValue)+cellValueAtRC i = atCell i . non def . cellValue++-- | lens to read, write or delete cell value in a worksheet+-- using traditional x+y coordinates+cellValueAtXY :: (Int, Int) -> Lens' Worksheet (Maybe CellValue)+cellValueAtXY = cellValueAtRC . swap
src/Codec/Xlsx/Types.hs view
@@ -52,6 +52,9 @@ instance Default Cell where def = Cell Nothing Nothing +-- | Map containing cell values which are indexed by row and column+-- if you need to use more traditional (x,y) indexing please you could+-- use corresponding accessors from ''Codec.Xlsx.Lens'' type CellMap = Map (Int, Int) Cell data RowProperties = RowProps { rowHeight :: Maybe Double, rowStyle::Maybe Int}@@ -70,7 +73,7 @@ { _wsColumns :: [ColumnsWidth] -- ^ column widths , _wsRowPropertiesMap :: Map Int RowProperties -- ^ custom row properties (height, style) map , _wsCells :: CellMap -- ^ data mapped by (row, column) pairs- , _wsMerges :: [Text]+ , _wsMerges :: [Text] -- ^ list of cell merges (entries of the form @D13:H14@) } deriving (Eq, Show) makeLenses ''Worksheet
xlsx.cabal view
@@ -1,6 +1,6 @@ Name: xlsx -Version: 0.1.1.1+Version: 0.1.2 Synopsis: Simple and incomplete Excel file parser/writer Description: