How to read Excel files in Unity?
Hello!
I've been working on a little project where I need a 2D array of strings. I thought a good way of storing those would be an Excel file. Its easy to edit and everyone knows how to use it. Only then I discovered that reading Excel files isn't a standard thing you can do in Unity. I did find something called NPOI but it wasn't clear to me how I could use it in unity.
So my question is :
Is there a way to read Excel files through C# in Unity?
I'm also open for other ways that make it possible to make a file that stores a 2D array of strings that can then be read with C#.
Answer by schnarch33 · Oct 19, 2017 at 02:09 PM
If you just need a 2D array stored in a seperate file, CSV files are definitely the way to go! They are simple and since you don't need any type of formation there shouldn't be any problems.
Related thread on Stackoverflow: https://stackoverflow.com/questions/3507498/reading-csv-files-using-c-sharp
This was exactly what I needed! Reading the CSV files was fairly easy and the only thing that took some work was putting it all into a 2D Array. Thank you for your answer!
Answer by UnityCoach · Oct 19, 2017 at 01:19 PM
Excel files are using an xml structure, so, in theory, you could use an xml parser to read it. Although, if you want to edit it outside of Unity, you can still use Excel (or Apple Numbers) and export a CSV file. It's quite easy to parse.
Otherwise, you can also create your own structure, edit it in the Editor and save it.
Here's some information on xml parsing. Or Json.
You could also save it as a ScriptableObject, and use an EditorWindow to display it.
Answer by Kishotta · Oct 18, 2017 at 10:46 PM
Microsoft does provide an Excel interop .dll, but I think you'd be better served with either:
1. PlayerPrefs, assuming the data you're storing is not vital to the game. (PlayerPrefs is just a .txt file in the game files. It can be edited by players.)
2. A database like SQLite. Databases take more time to setup, but have several advantages over an excel or text file (such as being more secure and more easily searchable for specific data).
Answer by MyUnitydream · Sep 12, 2018 at 05:03 AM
you can use Uni-Excel Package for Read, Write, and edit excel files
Answer by Priyanka-Rajwanshi · Dec 21, 2019 at 05:34 PM
The most convenient way to parse an excel sheet in Unity3D is to convert it into CSV. Check out this link: