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

Proposal: support constructing worksheets with lists of lists #26

Open
kojo12228 opened this issue Mar 27, 2022 · 4 comments
Open

Proposal: support constructing worksheets with lists of lists #26

kojo12228 opened this issue Mar 27, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@kojo12228
Copy link

Since F# London, I've been giving FsExcel a bit of thought and came to the conclusion that it might be nicer to work with if it supported using a list of lists.

Thus:

Render.AsFile': path: string -> items: Item list list -> unit

To be consistent with the current API, an Item list would be a row of cells, and an Item list list would be the grid of cells (collection of rows).

So taking examples from the README:

Multiple Cells

[
    [
        for i in 1..10 ->
            Cell [ Integer i ]
    ]
]
|> Render.AsFile' (Path.Combine(savePath, "MultipleCells.xlsx"))

Vertical Movement

[
    for m in 1..12 do
        let monthName = CultureInfo.GetCultureInfoByIetfLanguageTag("en-GB").DateTimeFormat.GetMonthName(m)
        [ Cell [ String monthName ] ]
]
|> Render.AsFile' (Path.Combine(savePath, "VerticalMovement.xlsx"))
[
    for m in 1..12 do
        [
            let monthName = CultureInfo.GetCultureInfoByIetfLanguageTag("en-GB").DateTimeFormat.GetMonthName(m)
            Cell [ String monthName ]
            Cell [ Integer monthName.Length ]
        ]
]
|> Render.AsFile' (Path.Combine(savePath, "Rows.xlsx"))

Absolute Positioning

For this example, I'm going to make another proposal for EmptyCell as a type of Item, by Go should still work in this system, it's probably need to be separated into distinct GoRow and GoCol. Go (RC(_, _)) wouldn't easily translate:

[
    [
        for i in 1..6 do
            if i = 3
            then Cell [ String "Col 3"]
            else EmptyCell
    ]
    []
    []
    [
        for i in 1..6 do
            if i = 4
            then Cell [ String "Row 4"]
            else EmptyCell
    ]
    []
    [
        for i in 1..6 do
            if i = 5
            then Cell [ String "R6C5"]
            elif i = 6
            then Cell [ String "R6C6"]
            else EmptyCell
    ]
]
|> Render.AsFile' (Path.Combine(savePath, "AbsolutePositioning.xlsx"))

For better type safety, AsFile' could be Render.AsFile': path: string -> items: Item [,] -> unit, but Array2D is definitely not as nice to work with compared to list comprehension.

This is pretty big change, so thought best to create an issue first. I would be happy to create a PR for this, just for the sake of playing around with the library more than anything.

@misterspeedy
Copy link
Owner

Oh this is very interesting. Let me have a think...

@misterspeedy
Copy link
Owner

Ok, @kojo12228, I've had a think about this and I love it! I've made a branch called ListOfLists.

Feel free to dive in straight away. Meanwhile I'll add a few 'getting started' tips in case you haven't worked it all out already.

Thanks for this.

@misterspeedy
Copy link
Owner

@kojo12228 I've now added a Contributing.md which outlines the setup and developer workflow:

https://github.com/misterspeedy/FsExcel/blob/main/Contributing.md

Honestly, I feel I've created a bit of a monster here so perhaps we should move away from having the tutorial generate the regression tests. Anyway, for now 'it is what it is'.

Hope you are able to try out that list-of-lists feature, it feels like it could be a big improvement.

Thankyou!

@kojo12228
Copy link
Author

Thanks @misterspeedy, I'm going to give it a try over the weekend hopefully.

@misterspeedy misterspeedy added the enhancement New feature or request label Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants