是否可以直接从xls文件读取数据到Deedle Frame?我发现Deedle.Excel具有openExcel方法,但无法使用它。如果可能,请提供示例。
安装deedle.excel和ExcelDataReader.DataSet之后,我使用下面的代码(我不确定这是否是最好的,但至少可以正常工作:]
using Deedle;
using ExcelDataReader;
// your code is omit
...
// below is the key code
Frame<int, string> mydf;
using (var stream = File.Open(myFilePath, FileMode.Open, FileAccess.Read))
{
using (var reader = ExcelReaderFactory.CreateReader(stream))
{
var result = reader.AsDataSet(new ExcelDataSetConfiguration()
{
UseColumnDataType = true,
ConfigureDataTable = (_) => new ExcelDataTableConfiguration()
{
UseHeaderRow = true, // to use the first row as header
}
});
DataTableReader rd = result.Tables[0].CreateDataReader(); //just use the first sheet
mydf = Frame.ReadReader(rd);
}
}
// use mydf below
...