Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8120511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:10:48+00:00 2026-06-06T05:10:48+00:00

I want to read a xls file and then parse it. How can i

  • 0

I want to read a xls file and then parse it. How can i do it with Lua? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T05:10:49+00:00Added an answer on June 6, 2026 at 5:10 am

    This isn’t a duplicate, since he actually just wants to read from an excel file and parse the data – not manipulate an excel object.

    Whenever I had to do this, I used luasql using ADO. at the most basic level, something like this is what you’d use to open a db connection and read excel data from it if you know how many fields are going to be in each row of your query.

    function rows(connection, sql_stmt)
        local cursor = assert(connection:execute(sql_stmt))
        return function() 
            return cursor:fetch()
        end
    end
    
    local fpath = "path/to/file.xlxs"
    local constr = "Provider=Microsoft.ACE.OLEDB.12.0;"..
                   "Data Source=\""..fpath.."\";".. 
                   "Extended Properties=\"Excel 12.0 Xml;HDR=YES\"";
                       
    local env = assert(luasql.ado())
    local con = assert(env:connect(constr))
    
    -- the name of the worksheet needs to be surrounded by brackets, and end
    -- with a '$' sign.
    local query = "SELECT * FROM \[name_of_worksheet$\]"
    
    -- you can do this if you know how many fields you get back specifically.
    for field1, field2, field3, ... in rows(con, query) do      
        -- handle any parsing of data from a row, here.
    end
    
    con:close()
    env:close()
    

    if you don’t know how many fields you’re getting back, you can do something like this:

    local fpath = "path/to/file.xlxs"
    local constr = "Provider=Microsoft.ACE.OLEDB.12.0;"..
                   "Data Source=\""..fpath.."\";"..
                   "Extended Properties=\"Excel 12.0 Xml;HDR=YES\"";
                       
    local env = assert(luasql.ado())
    local con = assert(env:connect(constr))
    
    -- the name of the worksheet needs to be surrounded by brackets, and end
    -- with a '$' sign.
    local query = "SELECT * FROM \[name_of_worksheet$\]"
    
    
    -- if you didn't know how many fields you might get back per row, i 
    -- believe you can do this to iterate over each row...
    local cursor = con:execute(query)
    local t = {}
    local results = cursor:fetch(t)
    
    while results ~= nil do
        for k,v in pairs(results) do
            -- check each field in the row here
        end
        results = con:fetch(t)
    end
    
    cursor:close()
    con:close()
    env:close()
    

    make sure to close your cursors/connections/environments when you’re done with them. also, you’ll want to verify that the connection string above will work with your version of excel. the easiest way to determine which connection string you need is to go to http://www.connectionstrings.com and browse for the correct one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to read data about MMORPG characters from a .txt file and then
I am trying to import an XLS file into PHP, where I can then
I have a text file. I want read that file. But In that if
I want to read lines from a file into a Set or List. Is
I want to read an existing PDF file, get not only the text, but
Hi I want to parse an excel file using zend framework. I went to
I want read the content of file and store it in array. I have
I have a perl script read Excel file and parse using a perl module
I want to read some code from a file and give this to a
I am trying to read an xls file in the column format: File Name

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.