使用 EPPlus 读取 Excel 电子表格 [英] Reading Excel spreasheet using EPPlus

查看:45
本文介绍了使用 EPPlus 读取 Excel 电子表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能指出我如何阅读 Excel 电子表格、遍历所有行和列以使用 EPPlus 和 MVC 检索值的正确方向吗?到目前为止,我看到了创建电子表格的示例,但在打开 excel 文件并从中读取值时没有找到任何示例.任何帮助将不胜感激.

Could someone point me in the right direction on how to read a Excel spreasheet, loop through all the rows and columns to retreive value using EPPlus and MVC? So fare I see examples to create a spreasheet, but did not find any on opening an excel file and read values from it. Any help would be appreciated.

TIA苏..

推荐答案

简单示例

// Get the file we are going to process
var existingFile = new FileInfo(filePath);
// Open and read the XlSX file.
using (var package = new ExcelPackage(existingFile))
{
    // Get the work book in the file
    var workBook = package.Workbook;
    if (workBook != null)
    {
        if (workBook.Worksheets.Count > 0)
        {
            // Get the first worksheet
            var currentWorksheet = workBook.Worksheets.First();

            // read some data
            object col1Header = currentWorksheet.Cells[1, 1].Value;

这篇关于使用 EPPlus 读取 Excel 电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆