Skip to content

Proposal: support constructing worksheets with lists of lists #26

@kojo12228

Description

@kojo12228

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions