简体   繁体   English

使用 exceldatareader 将 excel 工作表行 ID 获取到数据集中

[英]get excel sheet row id using exceldatareader into dataset

I have chosen the ExcelDataReader Library for Reading the.XLS and.XLSX files using C#.我选择了 ExcelDataReader 库来使用 C# 读取 .XLS 和 .XLSX 文件。 ExcelDataReader is perfectly working with both file formats with my local and deployment server environment. ExcelDataReader 在我的本地和部署服务器环境中完美地处理这两种文件格式。

I'm facing issue, how to get all the row id from given Excel files?我遇到了问题,如何从给定的 Excel 文件中获取所有行 ID?

INPUT Excel file:输入 Excel 文件:

在此处输入图像描述

And i want output in dataset format like that我想要像这样的数据集格式的 output

在此处输入图像描述

Lets explain by code让我们通过代码来解释

    using (var stream = System.IO.File.Open(Server.MapPath("yourExcelfileName.xlsx"), FileMode.Open, FileAccess.Read))
    {
        using (var reader = ExcelDataReader.ExcelReaderFactory.CreateReader(stream))
        {
            var conf = new ExcelDataSetConfiguration()
            {
                ConfigureDataTable = a => new ExcelDataTableConfiguration
                {
                    UseHeaderRow = true
                }
            };
            var dataSet = reader.AsDataSet(conf);
            var sheet = dataSet.Tables["sheetName"].Rows.Cast<DataRow>(); // instead of sheetName you can use Index of it like 0 ,1 , ...
            foreach (var row in sheet)
            {
                // some code
                var rowId = row.Table.Rows.IndexOf(row);
                var rowValueByHeaderFieldName = row["HeaderFieldName"]; // you can also use index instead of HeaderFieldName like row[1] , ...
                // some code
            }
        }
    }

Hope this help;)希望这有帮助;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 exceldatareader 获取 excel 表列名称 - get excel sheet column names using exceldatareader 使用ExcelDataReader将多个Excel工作表导入到GridView中 - Import multiple excel sheet into gridview using exceldatareader 始终使用ExcelDataReader从Excel文件中以字符串形式获取数据 - Always Get Data as String from Excel file using ExcelDataReader 如何使用C#在Azure函数中添加ExcelDataReader和Excel数据集的依赖项 - How to add the dependencies of ExcelDataReader and Excel dataset in Azure functions using C# DataSet无法使用ExcelDataReader清除旧数据 - DataSet not clearing old data using ExcelDataReader ExcelDataReader - 获取当前读取行的索引 - ExcelDataReader - Get index of currently read row 如何使用 ExcelDataReader 从 C# 中的 excel 文件中逐行(按行)获取数据 - How to fetch line by line (row wise) data from excel file in c# using ExcelDataReader 如何在Winform应用程序中获取Excel工作表的行和列ID - How can I get row and column id of an Excel sheet in my winform application 使用exceldatareader从excel文件中获取数据并将其粘贴到xml文件中? - Using exceldatareader to take data from excel file and paste it in a xml file? 使用ExcelDataReader时如何将多个Excel工作表作为数据表传递? - How to pass multiple Excel sheets as data table when using ExcelDataReader?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM