- Home /
Reading an excel file using ExcelReaderFacotry
Hi guys,
I'm probably just shouting in the wind here given I am using a 3rd party library (See: https://github.com/ExcelDataReader/ExcelDataReader). I started using this library as the mono implementation of reading excel file is broken for the 64bit version.
I have the ExcelDataReader functionality working in the Unity editor. I read an Excel file and store the data in memory. No problem.
I then build my game. I put the excel file into the _Data location. I run the game and now the Excel file is not being read.
Debugging using LogError shows the FileStream has been opened. There is no problem in opening the Excel file. It is in the correct location.
The problem is when I use the stream to CreateOpenXmlReader(). The excelReader.IsClosed is equal to True.
I don't understand why this is the case. The DLL's for the library are in the Managed Folder the Excel files are in the correct location.
Basically I'm asking anyone who has used ExcelDataReader and created a project build, is it solvable and how so? Thanks.
protected void OpenDataReader(string _filename) {
DataSet result;
_filename = string.Concat(Application.dataPath, "/Data/", _filename, ".xlsx");
FileStream stream = File.Open(_filename, FileMode.Open, FileAccess.Read);
**excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);** //IsClosed = True
result = excelReader.AsDataSet();
skipFirstRow = true;
}
I had to abandon that implementation and use a 3rd party CSV Reader. http://wiki.unity3d.com/index.php/CSVReader
I see. I was able to resolve the issue by upgrading the ExcelDataReader to the latest version (from 2.1.2.3 to 3.4.0). Unfortunately couldn't trace the problem to a specific issue/commit within the project.
Answer by MyUnitydream · Sep 12, 2018 at 05:12 AM
you can use Uni-Excel Package for Read, Write, and edit excel files