1、命名空间
using System.IO;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
2、代码
#region NPOI方式
/// <summary>
/// 本机无需安装Microsoft Excel
/// 1、将Excel文件数据(多个sheet页分为不同的表)导入到DataSet临时表中
/// 2、解析Excel表格列和行的格式
/// </summary>
/// <returns></returns>
public static DataSet ImportExe()
{
DataSet ds = new DataSet();
OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "Excel文件";
ofd.FileName = "";
ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
ofd.Filter = "所有文件(*.*)|*.*|Excel2003文件(*.xls)|*.xls|Excel2007文件(*.xlsx)|*.xlsx";
ofd.ValidateNames = true;
ofd.CheckFileExists = true;
ofd.CheckPathExists