So I have an sql database storing some information. I want to go into an excel spreadsheet where 10 digit phone numbers are all in cell A, and add the name of the individual in cell B next to cell A if the sql file has a match between the name and the number.
Here's what I made:
import xlrd
import sqlite3
import xlsxwriter
alpha = ("B")
bravo = 1
charlie = (alpha + str(bravo))
conn = sqlite3.connect('test.db')
c = conn.cursor()
c.execute(''' SELECT fname, lname, number FROM info''')
all_rows = c.fetchall()
for row in all_rows:
delta = ('{0}'.format(row[0])) # First Name
echo = ('{0}'.format(row[1])) # Last Name
foxtrot = ('{0}'.format(row[2])) # Phone Number
golf = (delta + echo) # Full Name
hotel = 0
book = xlrd.open_workbook("test.xlsx")
first_sheet = book.sheet_by_index(0)
cell = first_sheet.cell(hotel,0).value
if cell == foxtrot:
worksheet.write((charlie), golf)
bravo += 1
hotel += 1
What I've tried to do in my example above is:
- Make a variable that can change so I can go through all the cells in A column.
- Go to our database file and extract the relevant information.
- Break down all the information we've taken into variables so we can compare them.
- Read the excel file.
- Compare the number we have in the database with the one in the excel file.
- If there's a match write in the name.
I'm pretty sure my error lies in how I'm comparing excel cells with the information gathered from the database. Any help would be great. Thanks fellas.
Aucun commentaire:
Enregistrer un commentaire