Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Excel on Unity

Discussion in 'Scripting' started by torombolo89, Apr 10, 2017.

  1. torombolo89

    torombolo89

    Joined:
    Aug 25, 2015
    Posts:
    30
    Hello i really hope i can get an answer to this.

    If there any away to import an excel file to unity and use the values in the document.

    For Example :

    Getting information from Cells A1, A2, A3, into a C# script

    If the total sum of the rows = 15
    Then " do something."

    or can this be achieved by something else.

    I want to be able to import values from a spreadsheet and use them on different C# scripts instead of having to populate them manually inside unity.


    Any help is appreciated

    Thank you.
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,144
    Excel files themselves I believe are harder to access outside of Excel itself if I remember correctly. A .csv file may be easier. However, normally if you're storing data you can use .json or .xml files.

    But, could you give more info? Are these spreadsheets you generate just for data storing or is this something a user can create and then load into your game?
     
  3. torombolo89

    torombolo89

    Joined:
    Aug 25, 2015
    Posts:
    30

    The user will no access to the values, Im trying to do a Badge/Achievement system, where i get the data from Excel (outside of unity) import the Values to Unity and have Unity access those values then use them in a series of statements/conditions
    to see if they have unlocked the achievement or not.
     
  4. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,384
    CSV files are pretty easy to deal with and you can open them in excel with pretty formatting.
     
    Kiwasi likes this.
  5. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,144
    You'll still probably have better luck using xml or json in Unity. Or, as I mentioned (and @LaneFox added) csv files. Excel files themselves will probably be harder to deal with. It was a pain back when I use to work with them and was trying to integrate them into a c# program. Granted this was about 10 years ago, so it might be easier now, but I think you'll still have better luck with one of the other formats.

    We have an achievement system where requirements are stored on our backend server and then the users progress is tracked in their account. It's stored in json and on our server (no local storage so it's harder to cheat the system).
     
  6. torombolo89

    torombolo89

    Joined:
    Aug 25, 2015
    Posts:
    30
    Thank you very much for the information now i know what i need to be researching.
     
  7. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Plus one for csvs. They are pretty trivial to read and write in both Unity and Excel. You do loose much of the advanced features of excel.

    If you do want to use excel files directly, it might be easier to interface with VBA and have excel open and read the files for you. This probably means your clients must have excel installed.
     
  8. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,549
    How much data are you talking about? What version of Excel are you using?

    I was thinking something like a sqlite database might be easier if you want it to be included in your application. There are several different ones in the asset store but SimpleSQL seems to be the most popular.

    https://www.assetstore.unity3d.com/en/#!/content/3845

    For other desktop applications I have used http://www.spreadsheetgear.com/ which works really well and very fast for reading/writing. It is priced high of course. They still have older *.net versions available.

    https://www.spreadsheetgear.com/downloads/downloadlicensed.aspx

    They do have a 30 day trial version if you wanted to test that out and see if it works.
     
  9. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,531
    CSV isn't entirely trivial. This is a valid row:

    "12,34",foo,"I span
    multiple lines",""bar""

    It consists of these 4 fields:
    • 12,34
    • foo
    • I span(newline) multiple lines
    • "bar"
    Just something to keep in mind if you write your own CSV parser. There are decent open source CSV parsers, though.
     
  10. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,842
    Another option is to store your data in Google Sheets, and pull it down from the web.

    We do exactly that in our 2D fighting game Disturbing the 'Verse (now in Greenlight and KickStarter!), so the designer can tweak all sorts of stuff without even recompiling the game. We have a sheet for attack combos, another sheet for gameplay parameters, a third for all the text that appears in the game (which will make it trivial to localize), etc.

    My code that pulls this data down (in JSON format) writes a copy to a temp folder, and then when I'm ready to do a "real" build for distribution, I just grab the latest version of these, toss them into the Resources folder, and build them into the game. If those resources are included then we use them instead of accessing the web. So then we have a self-contained app that doesn't require a network connection.

    All this was a pain to set up, but it's pretty sweet now that it's humming along.
     
    TonyLi likes this.
  11. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,144
    That's an interesting idea...and a quick search found this
    https://github.com/kimsama/Unity-QuickSheet

    Which for the OP also mentions using excel. So might be worth a look.
     
    JoeStrout likes this.
  12. MyUnitydream

    MyUnitydream

    Joined:
    Jul 2, 2015
    Posts:
    22