如何从Excel工作表中读取数据并将其存储在MVC的数据库中? [英] how to read data from excel sheet and store it in database in MVC?
本文介绍了如何从Excel工作表中读取数据并将其存储在MVC的数据库中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用EPPlus从excel文件中读取数据。但我不知道该怎么办。请帮忙。
public ActionResult Index()
{
// OpenFileDialog fileDialog = new OpenFileDialog();
var path = Server.MapPath(〜/ App_Data / CompanyList.xls);
FileStream stream = new FileStream(path,FileMode.Open);
// FileStream str = System.IO.File.Open(fileDialog.FileName,FileMode.Open,FileAccess.Read);
readExcel2003(stream);
return View();
}
public DataSet readExcel2003(FileStream stream)
{
DataSet dataSet;
// 1。从二进制Excel文件读取('97 -2003格式; * .xls)
IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
dataSet = excelReader.AsDataSet();
excelReader.Close();
返回dataSet;
}
i收到错误找不到ExcelReaderFactory.cs
。
解决方案
IExcelDataReader
和ExcelDataReaderFactory
不属于 EPPlus [ ^ ],并且EPPlus不支持Excel 2003(.xsl
)文件。 />
听起来你正在使用ExcelDataReader
包 [ ^ ],你要么是避风港没有添加对项目的引用,或者你错过使用 Excel
命名空间的指令。
I am trying to read data from excel file using EPPlus. But i am not sure how to proceed. Please help.
public ActionResult Index() { //OpenFileDialog fileDialog = new OpenFileDialog(); var path=Server.MapPath("~/App_Data/CompanyList.xls"); FileStream stream = new FileStream(path, FileMode.Open); //FileStream str = System.IO.File.Open(fileDialog.FileName, FileMode.Open, FileAccess.Read); readExcel2003(stream); return View(); } public DataSet readExcel2003(FileStream stream) { DataSet dataSet; //1. Reading from a binary Excel file ('97-2003 format; *.xls) IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream); dataSet = excelReader.AsDataSet(); excelReader.Close(); return dataSet; }
i am getting error that ExcelReaderFactory.cs
is not found.
解决方案
IExcelDataReader
andExcelDataReaderFactory
are not part of EPPlus[^], and EPPlus does not support Excel 2003 (.xsl
) files.
It sounds like you're using theExcelDataReader
package[^], and you either haven't added the reference to your project, or you're missing ausing
directive for theExcel
namespace.
这篇关于如何从Excel工作表中读取数据并将其存储在MVC的数据库中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文