Skip to content
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

Worksheet -> [[Text]] function? #21

Open
mb21 opened this issue Aug 4, 2015 · 6 comments
Open

Worksheet -> [[Text]] function? #21

mb21 opened this issue Aug 4, 2015 · 6 comments

Comments

@mb21
Copy link

mb21 commented Aug 4, 2015

This is not really urgent, but I was thinking of adding xlsx support (in addition to csv) to the pandoc-placetable filter, so I'd need a Worksheet -> [[Text]] function.

I guess I could come up with the fold Map (Int, Int) Cell -> [[Cell]] myself somehow (although there might be a neater way using Lens.Traversal?), but how about a Cell -> Text function that preserves some styling for numbers (like number of significant digits, currency, scientific notation etc.)?

@qrilka
Copy link
Owner

qrilka commented Aug 4, 2015

Currently xlsx does not support cell formatting - Styles is just a wrapper around a bytestring. I suppose it is required for your filter, right?

@mb21
Copy link
Author

mb21 commented Aug 4, 2015

Yeah, I mean exporting to csv from a spreadsheet program usually preserves that kind of formatting... so without that I'm kind of hesitating to add xlsx as a dependency... thanks anyway :)

@qrilka
Copy link
Owner

qrilka commented Aug 4, 2015

I'll try to look into that area but no particular promises at the moment

qrilka pushed a commit that referenced this issue Dec 19, 2021
@olafklinke
Copy link

FWIW, I happened to implement something along these lines, because the xls package has this and I wanted a unified Megaparsec parser for both xlsx and xls. Here is the code:

import Control.Arrow (first)
import Data.Function (on)
import Data.List (groupBy)
import Data.Map.Strict (toAscList)
cellRows :: CellMap -> [[Cell]]
cellRows = fmap (fillBlanks . fmap (first snd)) . groupBy ((==) `on` (fst.fst)) . toAscList where
    fillBlanks :: [(Int,Cell)] -> [Cell]
    fillBlanks = go 0
    blankCell = Cell Nothing Nothing Nothing Nothing
    go :: Int -> [(Int,Cell)] -> [Cell]
    go _ [] = []
    go i ((j,c):cs) = replicate (j-i-1) blankCell ++ (c : go j cs) 

@qrilka
Copy link
Owner

qrilka commented May 17, 2024

@olafklinke could we worth creating a PR if you have time for it

@olafklinke
Copy link

@olafklinke could we worth creating a PR if you have time for it

IMHO this would actually better be part of a separate package, see here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants