Search Unity

Reading and using Excel

Discussion in 'Editor & General Support' started by wilhelmscream, Mar 18, 2019.

  1. wilhelmscream

    wilhelmscream

    Joined:
    Jun 5, 2013
    Posts:
    223
    This is puzzling the heck out of me.

    I'm looking for a way to read an Excel spreadsheet and convert that data into a list (or similar). In theory, I'm looking for something similar to the methodology of reading a .txt file to generate a list. Everything I have found so far (maybe 20 or so different threads, pages, answers etc) involves using Excel to generate code, create objects, etc....

    Or worse, is specific to writing to Excel, which I don't need to do. Is what I'm trying to do not feasible?
     
  2. digipaul

    digipaul

    Joined:
    Nov 24, 2018
    Posts:
    43
    you could save your xl file as a .csv file. This is a simple text file where each line contains a row of the spreadsheet
    with the values separated by commas. This would be simple to read into unity using string operations.
     
  3. trisogene

    trisogene

    Joined:
    Mar 18, 2019
    Posts:
    2
  4. Pricelove

    Pricelove

    Joined:
    Aug 29, 2016
    Posts:
    3
    Hello, try this:

    Code (CSharp):
    1. public TextAsset narrativeTextFile;
    2.  
    3.  
    4. string[] linesFromfile = narrativeTextFile.text.Split ("\n" [0]);
    5. string currentTxt = linesFromfile [index];
    The "TextAsset" file should be a .csv file.
     
  5. LillyB

    LillyB

    Joined:
    Nov 23, 2018
    Posts:
    11
    For converting your excel file you can use converter. There have some reliable converter on the Internet. Search for them.