2

Using the ExcelDataReader within a F# project. To use the first row as Column names (headers) the configuration needs to be adjusted with the following C# code:

var result = reader.AsDataSet(new ExcelDataSetConfiguration() {
    ConfigureDataTable = (_) => new ExcelDataTableConfiguration() {
        UseHeaderRow = true
    }
});

As is explained in https://github.com/ExcelDataReader/ExcelDataReader#important-note-when-upgrading-from-exceldatareader-2x

If I try to translate this to F# code:

let result = reader.AsDataSet (
  new ExcelDataSetConfiguration ( 
     ConfigureDataTable = ExcelDataTableConfiguration ( 
        UseHeaderRow = true)
     )
  )

I get the following error:

error FS0001: This expression was expected to have
type 'Func<IExcelDataReader,ExcelDataTableConfiguration>' but here has
type 'ExcelDataTableConfiguration'

If I understand well, I will have to pass a Linq expression, so I looked at some examples:

http://www.fssnip.net/ts/title/F-lambda-to-C-LINQ-Expression

How do I create a Linq expression tree with an F# lambda?

Unfortunately I didn't manage to solve this problem. Any pointers will be hugely appreciated!

Titus
  • 41
  • 1
  • 4
  • Property `ConfigureDataTable` is of type `Func<_,_>`, but you're trying to assign an `ExcelDataTableConfiguration` to it. – Fyodor Soikin Aug 23 '18 at 00:32
  • You're right, I was messing a bit with the F# lambda functions, but you pointed me to the answer: `let result = reader.AsDataSet(new ExcelDataSetConfiguration( ConfigureDataTable = fun (_:IExcelDataReader) -> ExcelDataTableConfiguration( UseHeaderRow = true)))` Thank you very much! – Titus Aug 23 '18 at 06:35

1 Answers1

2

Ok, more simple than I thought:

let result = reader.AsDataSet(
  new ExcelDataSetConfiguration( 
    ConfigureDataTable = 
      fun (_:IExcelDataReader) -> ExcelDataTableConfiguration( UseHeaderRow = true)
    )
  )

@Fyodor Soikin, thank you for the support!

Hope this helps others with the same issue.

Titus
  • 41
  • 1
  • 4