Currently, we have a project that runs on Windows and uses an Excel spreadsheet to save/retrive some data/information. Now we want to build that project for WebGL. The problem is that file reading support is not available on the WebGL platform. How do I solve this problem? Do I need to write a backend or there another way to use excel in WebGL platform even though the file reading API of the .NET framework is not supported on WebGL?
When your WebGL game needs to read an arbitrary file, then you can add it to the game build by turning it into a text asset. You need to rename it to give it the file extension
.bytes, so Unity recognizes it as a binary file (for example:
items.xlsx.bytes). To ensure that the file is included in the WebGL build, you need to store it in an Assets/Resources folder or in an asset bundle which you then export to your WebGL build.
If you decided to use resources:
TextAsset txt = Resources.Load("items.xlsx") as TextAsset;
If you decided to use an asset bundle:
AssetBundle bundle = myLoadedAssetBundle = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "myassetBundle")); TextAsset txt = bundle.Load("items.xlsx", typeof(TextAsset)) as TextAsset;
Now you can get the binary data from that text asset with
byte bytes = txt.bytes;
and feed it into the code you already have for parsing Excel workbooks.