excel - 如何使用epplus循环读取excel中的列标题

标签 excel c#-4.0 epplus

我正在使用 epplus 读取一个 excel 文件,我想遍历每一行和每一列并查找列标题以检查集合并读取单元格值是否匹配。我是 epplus 的新手,找不到任何引用来做这样的事情。我在 this link 中研究了类似的问题,但我没有通过列标题循环的东西。

有没有可能这样做?任何帮助深表感谢。

谢谢!

最佳答案

如果要在 Excel 文件中查找与您指定的名称匹配的列,可以使用此函数:

    public string FindColumnAddress(ExcelWorksheet sheet, string columnName)
    {

        int totalRows = sheet.Dimension.End.Row;
        int totalCols = sheet.Dimension.End.Column;
        var range = sheet.Cells[1, 1, 1, totalCols];
        for (int i = 1; i <= totalCols; i++)
        {
            if (range[1, i].Address != "" && range[1, i].Value != null && range[1, i].Value.ToString() == columnName)
                return range[1, i].Address;

        }
        return null;
    }

它将返回列标题的地址。
您可以将其更改为返回 i 作为列的索引。

关于excel - 如何使用epplus循环读取excel中的列标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25629085/

相关文章:

java - 如何在使用 POI 生成的 Excel 工作表中创建依赖下拉列表?

winapi - Google 登录并在 Windows Phone 8.1 WinRT 应用程序中检索个人资料信息

mysql - 从 Controller 返回查询而不是值的数据库查询

excel - 使用 Matlab 忽略比例将 Excel 文件转换为 PDF

sql - Excel导入Access

asp.net-mvc-4 - 使用数据注释传递错误消息字符串

c# - 如何获取 EPPlus OpenXML 行数 (c#)

c# - 在 EPPlus C# 中展开表

excel - 根据他们的位置对excel中的数字进行评级

c# - mef 中的意外结果