-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proof-of-concept decode XLS from ByteString, typed cells #9
base: master
Are you sure you want to change the base?
Changes from all commits
bc3f917
4925ca7
5e1a09a
e899008
4e7a2ba
f25086e
a76b586
49059e2
92828db
f56ee77
63a87ca
068856d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
-- | | ||
-- Module : Data.XlsCell | ||
-- Copyright : (c) 2022 Olaf.Klinke | ||
-- | ||
-- License : BSD-style | ||
-- Maintainer : [email protected] | ||
-- Stability : experimental | ||
-- Portability : GHC | ||
-- | ||
-- Static Excel cell values | ||
-- | ||
{-# LANGUAGE DeriveFunctor, FlexibleInstances #-} | ||
module Data.XlsCell (CellF(..),Cell,cellToString) where | ||
import Data.String (IsString(..)) | ||
import Text.Printf (printf) | ||
|
||
-- | extensible 'Cell' type | ||
data CellF o = NumericalCell Double | ||
| TextCell String | ||
| BoolCell Bool | ||
| OtherCell o | ||
deriving (Functor,Show,Eq) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a way/possiblity for users to use this type? otherwise we should not expose this type and if that's the case then we can just use a |
||
instance IsString (CellF o) where | ||
fromString = TextCell | ||
|
||
-- | static 'Cell's in Excel files can hold | ||
-- numbers, test or booleans. | ||
type Cell = CellF () | ||
|
||
-- | convert to 'String'. Not the inverse of 'fromString'! | ||
cellToString :: Cell -> String | ||
cellToString (NumericalCell d) = printf "%.15g" d | ||
cellToString (TextCell txt) = txt | ||
cellToString (BoolCell b) = if b then "True" else "False" | ||
cellToString (OtherCell _) = "" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name: xls | ||
version: 0.1.3 | ||
version: 0.1.4 | ||
synopsis: Parse Microsoft Excel xls files (BIFF/Excel 97-2004) | ||
description: | ||
Parse Microsoft Excel spreadsheet files in @.xls@ file format | ||
|
@@ -49,10 +49,13 @@ library | |
|
||
hs-source-dirs: lib | ||
exposed-modules: Data.Xls | ||
other-modules: Data.XlsCell | ||
build-depends: base >= 4.7 && < 5 | ||
, bytestring >= 0.10 | ||
, conduit >= 1.1 && < 1.4 | ||
, filepath >= 1.0 && < 1.5 | ||
, resourcet >= 0.3 && < 1.3 | ||
, temporary | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can add bounds here. Also, bounds of transformers and resourcet can be bumped up. |
||
, transformers >= 0.1 && < 0.6 | ||
|
||
c-sources: lib/libxls-wrapper.c, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you suggest to make
XLSError
an instance ofException
and usethrowIO
instead of explicitly returningEither
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is somewhat odd that there are two exception types:
XLSError
from libxls and theXlsException
defined in this package. Proposal: We addXLSError
into theXlsException
type so that only one exception type is thrown by this library.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created a branch in my fork for unifying the error types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created a branch in my fork for unifying the error types.