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

The Table.fromSeq feature only supports F# records #25

Open
misterspeedy opened this issue Mar 26, 2022 · 0 comments
Open

The Table.fromSeq feature only supports F# records #25

misterspeedy opened this issue Mar 26, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@misterspeedy
Copy link
Owner

For example, this causes an error:

open System.Data
open FsExcel
open ClosedXML.Excel

let table = new DataTable("Fruits")

let id = new DataColumn()
id.ColumnName <- "Id"
table.Columns.Add(id)

let name = new DataColumn()
name.ColumnName <- "Name"
table.Columns.Add(name)

let averageWeightG = new DataColumn()
averageWeightG.ColumnName <- "AverageWeightG"
table.Columns.Add(averageWeightG)

for id, name, averageWeightG in [1, "Apple", 100; 2, "Pear", 110; 3, "Banana", 120] do
    let row = table.NewRow()
    row["Id"] <- id
    row["Name"] <- name
    row["AverageWeightG"] <- averageWeightG
    table.Rows.Add(row)

let cellStyleHorizontal index name =
    if index = 0 then
        [
            Border(Border.Bottom XLBorderStyleValues.Medium)
            FontEmphasis Bold
        ]
    elif name = "Fees" then
        [ FormatCode "$0.00" ]
    else
        []    

seq {for row in table.Rows -> row}
|> Table.fromSeq Table.Direction.Horizontal cellStyleHorizontal
|> fun cells -> cells @ [ AutoFit All ]
|> Render.AsFile (Path.Combine(savePath, "RecordSequenceVertical.xlsx"))

Error: System.ArgumentException: Type 'System.Data.DataRow' is not an F# record type. (Parameter 'recordType')
at Microsoft.FSharp.Reflection.Impl.checkRecordType(String argName, Type recordType, BindingFlags bindingFlags) in D:\a_work\1\s\src\fsharp\FSharp.Core\reflect.fs:line 849
at FsExcel.Table.Fields.serializable@16.Invoke(Type _arg1)
at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory)
at FsExcel.Table.Fields.serializable(Type t)
at FsExcel.Table.Cells.header[T](FSharpFunc2 getCellStyle) at FsExcel.Table.fromSeq[T](Direction direction, FSharpFunc2 getCellStyle, IEnumerable`1 xs)
at <StartupCode$FSI_0025>.$FSI_0025.main@()

@misterspeedy misterspeedy added the bug Something isn't working label Apr 25, 2022
@misterspeedy misterspeedy added enhancement New feature or request and removed bug Something isn't working labels Mar 10, 2023
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

1 participant