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#.

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

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).

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][1].
Or

[2].

You could also save it as a [ScriptableObject][3], and use an [EditorWindow][4] to display it.


  [1]: http://wiki.unity3d.com/index.php?title=Saving_and_Loading_Data:_XmlSerializer
  [2]: https://docs.unity3d.com/ScriptReference/JsonUtility.html
  [3]: https://docs.unity3d.com/ScriptReference/ScriptableObject.html
  [4]: https://docs.unity3d.com/ScriptReference/EditorWindow.html

you can use Uni-Excel Package for Read, Write, and edit excel files

The most convenient way to parse an excel sheet in Unity3D is to convert it into CSV. Check out this link:

http://codesaying.com/unity-parse-excel-in-unity3d/