相关疑难解决方法(0)

ExcelReaderFactory,读取第一张表

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)

c# excel

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×1

excel ×1