How to read a excel table?

hello so i have a big excel table in a .csv file with 10k cities and info about them i wanna read it is there a way to do it? for example with something like StudioService:PromptImportFile ?
i want to make it into a lua dictionary something like this:


local cities = {

['New York'] = {
long = 0
lat = 0
population = 0
-- the info
}


}

never mind found the solution

You already said you have solved it, but it might be a good idea to share the solution with others, to avoid duplicate questions.

ok so basically open the excel with notepad it should give you a bunch of text, you copy it and do this

local CSV =
    [[
-- The text you copied
       ]]

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
		
		task.wait()
		table.insert(rows, row)
	end

	return rows
end

local CSV_Table = parseCsv(CSV)

this should make the excel into a table that you can use it will not make it a dictionary tho thats the only downside

1 Like