Is it possible to import Excel or Python data?

  1. What do you want to achieve? Keep it simple and clear!

I want to import Excel data.

  1. What is the issue? Include screenshots / videos if possible!

I want to import Excel Data

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I have searched here for weeks. I used the keywords like Excel, table, etc.
But I could not find a good answer.

Hello Everyone.

I am a novice developer but have developed several games so far including the followings.

Math Obby & Playgrounds

Math Obby & Playgrounds 2

Fraction’s Pizza Obby

In these 3 games, basically obby blocks are consisted of quiz boards so that players can learn about math.

Now I am developing an ESL game in which players can learn about English grammar.
And I am developing a quiz board set now.
For math game, making quiz boards were not so hard because targets are numbers
and I could use random() to generate questions and answers automatically.

However, for English grammar, it looks more complicated.
So I want to prepare Excel file like below:

If I can import this kind of Excel files into Roblox Studio and prepare the matrix data,
I think it would be much easier to make the new game.

If it is impossible to import Excel data, is it possible to import Python data?
(Because I can convert Excel file to Python file with pandas.)

And so I will appreciate if you guys give me any advice or idea.

3 Likes

Why not just convert the excel data into text then using string manipulation to turn it into a table.

2 Likes

Thank you for the quick reply.
Does “text” mean CSV file?
Is it possible to import CSV file?

One reason I want to use Excel is for data management
because these questions and answers may be changed often.
I want to use cell reference and only change Excel file if possible.

Another reason I want to use Excel is for players including teachers and parents.
In the future I want they make question and answer set by themselves and so
the handling should be easy and simple, and I believe many of them are familiar with Excel.

There’s plenty of libraries to convert csv files to json data. One of those is literally called csv to json. So figure out how to use it from there, once you got your setup done just stringify that json array and set it as a response header in a node server (javascript). Then setup that server either on your localhost if this is a one time thing or use heroku to set it up and use http service to get the data from that

2 Likes

A way I would approach is send a request from studio to a python webserver or something , where you use pandas to read the csv file and convert it to json and return it , with the returned json you can assign create the Excel frame easily since its key-value based.

2 Likes

Thank you for your reply. Now I found Roblox can handle JSON data. So maybe I got the flow, that is, Excel > CSV > JSON > Roblox Lua.

Thank you for your reply. I am not sure how to send the request from Studio to a python webserver, so I will research more.

You can use HTTPService to send the request.

1 Like

Before you start setting up a server and everything, consider if it’s acceptable for you to just copy/paste some text from a file into a ModuleScript whenever you make a change. You can just open any CSV file in notepad and copy/paste the text into Studio. You can then parse the CSV into a table like so:

local csv = 
[[
1,I ( ) you.,love,loves,loved,will love
2,He ( ) pork.,hate,hates,hated,will hate
3,She ( ) beef.,eats,eat,ate,will eat
]]

local linePattern = "[^\r\n]+"
local csWordPattern = "[^,]+"

function parseCsv(csv)
    local rows = {}
    
    for line in string.gmatch(csv, linePattern) do
        local row = {}
        
        for word in string.gmatch(line,csWordPattern) do
            table.insert(row, word)
        end

        table.insert(rows, row)
    end
    
    return rows
end

local sheet = parseCsv(csv)
print(sheet[3][2]) --prints 'She ( ) beef.'
2 Likes

I c. I will definitely check HTTPService. Thank you!

It really depends on whether the data is static (will it have to change) or not. Importing the data using HTTP requests as @Razor_IB mentioned is probably the cleanest way, since you can easily make adjustments in Google Sheets for example.

The limitations of the Google Sheets API are actually quite okay: Usage Limits  |  Sheets API  |  Google Developers.

This version of the Google Sheets API has a limit of 500 requests per 100 seconds per project, and 100 requests per 100 seconds per user.

On the other hand, simply importing the data as a table is the easiest option if your data is completely static.

1 Like

Thank you for the specific code. This is very educational.

Yes, it might be better if I don’t set up a server because I have little knowledge of server things now, although I would need it in my future games.

Well, I think my data for this game is static, although maybe I need to change the data sometimes.
Google Sheet is another good idea though, which may be useful for other games.