xlsx-1.1.2.2: Simple and incomplete Excel file parser/writer

Safe Haskell | Safe-Inferred
Language | Haskell2010

Codec.Xlsx.Writer.Stream

Contents

- Shared strings

Description

Writes Excel files from a stream, which allows creation of large Excel files while remaining in constant memory.

Synopsis

- writeXlsx :: MonadThrow m => PrimMonad m => SheetWriteSettings -> ConduitT () Row m () -> ConduitT () ByteString m Word64
- writeXlsxWithSharedStrings :: MonadThrow m => PrimMonad m => SheetWriteSettings -> Map Text Int -> ConduitT () Row m () -> ConduitT () ByteString m Word64
- data SheetWriteSettings = MkSheetWriteSettings {
  - _wsSheetView :: [SheetView]
  - _wsZip :: ZipOptions
  - _wsColumnProperties :: [ColumnsProperties]
  - _wsRowProperties :: Map Int RowProperties
  - _wsStyles :: Styles
  }
- defaultSettings :: SheetWriteSettings
- wsSheetView :: Lens' SheetWriteSettings [SheetView]
- wsZip :: Lens' SheetWriteSettings ZipOptions
- wsColumnProperties :: Lens' SheetWriteSettings [ColumnsProperties]
- wsRowProperties :: Lens' SheetWriteSettings (Map Int RowProperties)
- wsStyles :: Lens' SheetWriteSettings Styles
- sharedStrings :: Monad m => ConduitT Row b m (Map Text Int)
- sharedStringsStream :: Monad m => ConduitT Row (Text, Int) m (Map Text Int)

# Documentation

writeXlsx Source #

Arguments

:: MonadThrow m |
=> PrimMonad m |
=> SheetWriteSettings | use `defaultSettings`
-> ConduitT () Row m () | the conduit producing sheetitems
-> ConduitT () ByteString m Word64 | result conduit producing xlsx files

Transform a `Row` stream into a stream that creates the xlsx file format (to be consumed by sinkfile for example) This first runs `sharedStrings` and then `writeXlsxWithSharedStrings`. If you want xlsx files this is the most obvious function to use. the others are exposed in case you can cache the shared strings for example.

Note that the current implementation concatenates everything into a single sheet. In other words there is no support for writing multiple sheets

writeXlsxWithSharedStrings Source #

Arguments

:: MonadThrow m |
=> PrimMonad m |
=> SheetWriteSettings |
-> Map Text Int | shared strings table
-> ConduitT () Row m () |
-> ConduitT () ByteString m Word64 |

This write Excel file with a shared strings lookup table. It appears that it is optional. Failed lookups will result in valid xlsx. There are several conditions on shared strings,

1. Every text to int is unique on both text and int.
2. Every Int should have a gap no greater than 1. [("xx", 3), ("yy", 4)] is okay, whereas [("xx", 3), ("yy", 5)] is not.
3. It's expected this starts from 0.

Use `sharedStringsStream` to get a good shared strings table. This is provided because the user may have a more efficient way of constructing this table than the library can provide, for example through database operations.

data SheetWriteSettings Source #

Settings for writing a single sheet.

Constructors

MkSheetWriteSettings |

Fields

- _wsSheetView :: [SheetView]
- _wsZip :: ZipOptions

  Enable zipOpt64=True if you intend writing large xlsx files, zip needs 64bit for files over 4gb.

- _wsColumnProperties :: [ColumnsProperties]
- _wsRowProperties :: Map Int RowProperties
- _wsStyles :: Styles

#### Instances

Instances details

Show SheetWriteSettings Source # |
Instance details Defined in Codec.Xlsx.Writer.Stream Methods showsPrec :: Int -> SheetWriteSettings -> ShowS Source # show :: SheetWriteSettings -> String Source # showList :: [SheetWriteSettings] -> ShowS Source #

defaultSettings :: SheetWriteSettings Source #

wsSheetView :: Lens' SheetWriteSettings [SheetView] Source #

wsZip :: Lens' SheetWriteSettings ZipOptions Source #

wsColumnProperties :: Lens' SheetWriteSettings [ColumnsProperties] Source #

wsRowProperties :: Lens' SheetWriteSettings (Map Int RowProperties) Source #

wsStyles :: Lens' SheetWriteSettings Styles Source #

### Shared strings

sharedStrings :: Monad m => ConduitT Row b m (Map Text Int) Source #

Process sheetItems into shared strings structure to be put into `writeXlsxWithSharedStrings`

sharedStringsStream :: Monad m => ConduitT Row (Text, Int) m (Map Text Int) Source #

creates a unique number for every encountered string in the stream This is used for creating a required structure in the xlsx format called shared strings. Every string get's transformed into a number

exposed to allow further processing, we also know the map after processing but I don't think conduit provides a way of getting that out. use `sharedStrings` to just get the map