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

  • Home
  • SEARCH
  • 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 7935765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:01:15+00:00 2026-06-03T22:01:15+00:00

I have an excel file which I am trying to put into mysql. There

  • 0

I have an excel file which I am trying to put into mysql. There are 32 fields which I want to extract using the python plugin xlrd and put into mysql. The data is laid out like so:

Data Layout

My methodology is to iterate over the rows and columns, adding fieldnames as I go. The code adds the field name but then there is an error when adding the data. (I created the table ‘OilProvedReservesHistory’ with an index as the only field):

SQL Layout

def get_data_from_sheet(sheet_index, table, start_row, end_row, end_col):

for row in range(start_row - 1, end_row - 1):
    for col in range(end_col):
        cell = sheet.cell(row,col)
        if col == 0:        
            fieldname = cleanup_field(cell.value)
            if fieldname != ("Blank Cell"):
                sql = "ALTER TABLE OilProvedReservesHistory ADD %s VARCHAR(20)" % fieldname
                c.execute(sql)                  
        else:
            data = cleanup_data(cell)
            if data != ("Blank Cell"):
                postToMySQL(data,fieldname,table)


def postToMySQL(data,fieldname,table):
#Generate sql query string                
sql = "INSERT INTO " + table + " ("+ fieldname + ") VALUES %s"
c.execute(sql, data)
# Executes: ("""INSERT INTO OilProvedReservesHistory (US) VALUES 36.533""")

table = create_table_from_sheet_name()

sheet_index = 0
start_row = 5
end_row = 68
end_col = 32

get_data_from_sheet(sheet_index, table, start_row, end_row, end_col)

The error I get is:

_mysql_exceptions.ProgrammingError: (1064, “You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ”36.533” at line 1″)

Can you help me get this working? Thanks a lot!

  • 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-03T22:01:16+00:00Added an answer on June 3, 2026 at 10:01 pm

    My guess is that you simply forgot the parenthesis for your VALUES clause.

    INSERT INTO OilProvedReservesHistory (US) VALUES (36.533)
    

    Try changing your code to:

    sql = "INSERT INTO " + table + " ("+ fieldname + ") VALUES (%s)"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Excel file that I am trying to load into R using
I have an Excel-Macro in VBA in which I want to copy the file
1) I'm trying to create CSV file using NSMutableArray(array of array) which I want
I have an excel file which is refreshing data every few seconds and running
I have this excel file which I have been able to write the data
I have some URLs in an Excel file which I have saved as a
I have an Excel file with one column which is filled with numbers. I
I have few text and excel file, from which I need to import data
I have an Excel file that I need to import into a (new) Oracle
I have an excel file that I want to embed in my C# assembly.

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.