c# NPOI读取excel2010

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using NPOI.XSSF.UserModel;
using NPOI.SS.UserModel;

namespace CheckWork
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnInput_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "Excel|*.xlsx|Excel|*.xls";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                //打开选择的Excel文件
                using (FileStream file = new FileStream(ofd.FileName, FileMode.Open))
                {
                    //根据现有的Excel文档创建工作簿
                    XSSFWorkbook workbook = new XSSFWorkbook(file);
                    //获得工作表
                    ISheet sheet0 = workbook.GetSheetAt(0);
                    //获得所有行的集合
                    System.Collections.IEnumerator rows = sheet0.GetRowEnumerator();
                    //跳过第一行
                    rows.MoveNext();
                    //向下移动
                    while (rows.MoveNext())
                    {
                        //获得当前行
                        XSSFRow row = rows.Current as XSSFRow;
                        //获取第一个格子的值
                        MessageBox.Show(row.GetCell(0).ToString());

                    }
                   
                }
            }
        }
    }
}
原文地址:https://www.cnblogs.com/yzw-carrie/p/5951868.html