我ExcelDataReaderFactory在 C# 中使用 ,以便读取我的 Excel 文件并将它们插入到数据库中。
现在我正在指定sheetname我想要使用的工作表。我可以让它每次都被选为第一张吗?
这是我加载数据的方式。
public IExcelDataReader getExcelReader()
{
// ExcelDataReader works with the binary Excel file, so it needs a FileStream
// to get started. This is how we avoid dependencies on ACE or Interop:
FileStream stream = File.Open(_path, FileMode.Open, FileAccess.Read);
// We return the interface, so that
IExcelDataReader reader = null;
try
{
if (_path.EndsWith(".xls"))
{
reader = ExcelReaderFactory.CreateBinaryReader(stream);
}
if (_path.EndsWith(".xlsx"))
{
reader = ExcelReaderFactory.CreateOpenXmlReader(stream);
}
return reader;
}
catch …Run Code Online (Sandbox Code Playgroud)