Export/import to excel file at runtime (PC/Mac/Linux only). If you are looking for Unity Editor solution, visit this page.
- Import/export database data from/to Excel file at runtime (in builds)
- Optionally, monitor excel file and auto-import the data if file is modified on disk.
- Import the latest BGDatabase package and create your own database as described here
- Import this plugin
- Now you need to add NPOI dlls to runtime assembly.
- If you use this plugin- dlls are located in Editor assembly. Move (not copy!) Assets\BansheeGz\BGDatabase\Editor\Libs\NPOI folder to Assets folder (or to any other folder, which is not under Editor folder) Select all dlls under Assets\NPOI, and in the inspector toggle "Any Platform" on, unselect any toggle under "Excluded Platforms" and click on "Apply" button (see the screenshot below)
- If you do not use Excel plugin, download and import this package with NPOI DLLs
- Export required data to Excel as described here
Assets\BansheeGz\BGDatabaseExcelRuntime\BGExcelImportGo.cscomponent to a new GameObject
- Set BGExcelImportGo's "Excel File" parameter to previously exported excel file location.
Use absolute path or path, relative to StreamingAssets folder if your excel file is located under StreamingAssets folder
(for example, for
Assets\StreamingAssets\excel.xlsxfile the correct value would be
- [Optionally] Toggle "Monitor File" parameter on to monitor the file. If it's set to true, a background thread is used to monitor the file and auto-import data on file change.
- [Optionally] Toggle "Import On Start" on to run import on scene load (from Start method)
- Run your scene
- Open excel file, change the data and save the file (Ctrl+s shortcut)
- If you set "Monitor File" parameter on, database data should be updated automatically. If "Monitor File" is off, you need to open BGExcelImportGo GUI by clicking on "Excel>>" button and then click on "Import" button to import the data. All binders in the scene will be executed after that.
- Click on "Excel>>" button to access BGExcelImportGo's runtime GUI. Make sure there was not any error while importing. Some people reported "Encoding XXX data could not be found" error (highlighted in red) while running import from built application, see the solution in "Troubleshooting" section below
- To export click on "Export" button or call BGExcelImportGo.Export method from your script. If you set "Export Meta only if sheet exists", export will ignore all tables which does not have corresponding sheet in target xls file
We have created an example project, which can be downloaded here. It works in both Unity Editor and PC builds and hopefully could help to start using this plugin.
Example project setup:
- Download the project zip file, unzip it and open in Unity Editor. Ignore console errors.
- Import BGDatabase package (version >= 1.6)
- Open BGDatabase window (Window->BG Database) and choose Database->test to see database data
- Run Scenes\SampleScene.unity scene
- Open StreamingAssets\excel.xlsx file, change
B2cell value and save the file (Ctrl+s). Value in the database and on screen will be changed
- If you want to test it in the build, build the application and run it.
Since we use relative excel path (not absolute), your Excel file location will be
Example project environment:
- NPOI library is imported
- Internationalization DLLs (I18N*.dll) are copied from
Assets/I18folder to avoid issues with missing encodings (see "Troubleshooting" section below for more information)
BGExcelImportGocomponent is attached to
ExcelManagergame object. It references
excel.xlsxfile, located under StreamingAssets folder (using relative path). Also, it has
Monitor fileparameter toggled on to enable file monitoring and auto-import data on file modification
- Data binder is used to inject value from the database to the Unity's UI Text component
Some people experienced "Encoding 1252 data could not be found" error while running export/import at runtime.
The solution: copy all "internationalization" dlls (I18N, I18N.West.dll etc. ) to your project as described
Note: there are multiple folders with different versions of I18 DLL files under your Unity installation folder.
The DLLs which fixed the error for us (with Unity 2020) are located under
- Some people reported "Error: No data is available for encoding 10001. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method." exception while trying to read xls file. The solution is- to import this package to your project.
|1.2||Aug 27, 2021||
|1.1||May 26, 2021||ADDED: export/import settings|
|1.0||Sep 16, 2020||Versioning reset (unified plugin infrastructure)|
|0.1.4||August 12, 2020||
|0.1.3||July 31, 2020||Support for xlsx files|
|0.1.2||July 08, 2020||Support for loading xls file from StreamingAsset folder by relative path|
|0.1.1||February 22, 2020||Export is added|
|0.1.0||July 22, 2019||Initial release|