39 lines
1.4 KiB
C#
39 lines
1.4 KiB
C#
using System.Data;
|
|
using System.IO;
|
|
//using Excel;
|
|
using ExcelDataReader;
|
|
using UnityEngine;
|
|
/*******************************************************************************
|
|
*Create By CG
|
|
*Function excel文件操作
|
|
*******************************************************************************/
|
|
namespace ZXK.UTility
|
|
{
|
|
public static class ExcelFileHandle
|
|
{
|
|
public static DataSet ReadExcel(string filePath)
|
|
{
|
|
FileStream stream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
|
//IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);//读取 Excel 1997-2003版本
|
|
IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);//读取 2007及以后的版本
|
|
DataSet result = excelReader.AsDataSet();
|
|
if (stream != null)
|
|
{
|
|
stream.Close();
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public static DataSet ReadExcel(Stream fileStream)
|
|
{
|
|
//IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(fileStream);//读取 Excel 1997-2003版本
|
|
IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(fileStream);//读取 2007及以后的版本
|
|
DataSet result = excelReader.AsDataSet();
|
|
if (fileStream != null)
|
|
{
|
|
fileStream.Close();
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
} |