Downloads

< Back to downloads

Excel export/import and file monitor for Runtime

Version:
1.0
Format:
Unity package
Dependencies:
BGDatabase (version >= 1.6)

Description

Export/import to excel file at runtime (PC/Mac/Linux only).

Features

  1. Import/export database data from/to Excel file at runtime (in builds)
  2. Optionally, monitor excel file and auto-import the data if file is modified on disk.

GUI overview

Setup

  1. Import BGDatabase package (version >= 1.6) and create your own database as described here
  2. Import this plugin
  3. Now you need to add NPOI dlls to runtime assembly.
    1. 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)
    2. If you do not use Excel plugin, download and import this package with NPOI DLLs
  4. Export required data to Excel as described here
  5. Add Assets\BansheeGz\BGDatabaseExcelRuntime\BGExcelImportGo.cs component to a new GameObject
  6. 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.xlsx file the correct value would be excel.xlsx)
  7. [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.
  8. [Optionally] Toggle "Import On Start" on to run import on scene load (from Start method)
  9. Run your scene
  10. Open excel file, change the data and save the file (Ctrl+s shortcut)
  11. 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.
  12. 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
  13. 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

Example project

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:
  1. Download the project zip file, unzip it and open in Unity Editor. Ignore console errors.
  2. Import BGDatabase package (version >= 1.6)
  3. Open BGDatabase window (Window->BG Database) and choose Database->test to see database data
  4. Run Scenes\SampleScene.unity scene
  5. Open StreamingAssets\excel.xlsx file, change B2 cell value and save the file (Ctrl+s). Value in the database and on screen will be changed
  6. 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 {YOUR_BUILD_FOLDER}/ExcelRuntime3_Data\StreamingAssets\excel.xlsx
Example project environment:
  1. NPOI library is imported
  2. Internationalization DLLs (I18N*.dll) are copied from {UNITY_FOLDER}\Editor\Data\MonoBleedingEdge\lib\mono\unityaot\ folder to Assets/I18 folder to avoid issues with missing encodings (see "Troubleshooting" section below for more information)
  3. BGExcelImportGo component is attached to ExcelManager game object. It references excel.xlsx file, located under StreamingAssets folder (using relative path). Also, it has Monitor file parameter toggled on to enable file monitoring and auto-import data on file modification
  4. Data binder is used to inject value from the database to the Unity's UI Text component

Troubleshooting

  1. 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 here 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 {UNITY_FOLDER}\Editor\Data\MonoBleedingEdge\lib\mono\unityaot\ folder
  2. 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.

Releases

Version Release date Log
1.0 Sep 16, 2020 Versioning reset (unified plugin infrastructure)
0.1.4 August 12, 2020
  1. FindObjectsOfTypeAll is replaced with Resources.FindObjectsOfTypeAll while searching for binders to include disabled binders
  2. File path Trim() is added to allow spaces in file path
  3. Example scene is removed, cause new example project is uploaded
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