Advertisement
shanonx

NewUser Excel Pull

Jul 7th, 2016
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | None | 0 0
  1. """Trying to import data from excel sheet and assign it to values of a class. I can get it to print the values, but cannot think of how to assign it to each individual attribute of the class newUser."""
  2.  
  3. from openpyxl import load_workbook
  4.  
  5. wb = load_workbook(filename='test.xlsx', use_iterators=True)
  6. ws = wb['accounts_needed'] # Sets ws to be iterable
  7.  
  8. class newUser:
  9.  
  10.     def __init__(self, firstname, lastname, email, password, campus, teks_username, google_username, discovery_username ):
  11.         self.firstname = firstname
  12.         self.lastname = lastname
  13.         self.email = email
  14.         self.password = password
  15.         self.campus = campus
  16.         self.teks_username = teks_username
  17.         self.google_username = google_username
  18.         self.discovery_username = discovery_username
  19.  
  20. for row in ws.iter_rows(row_offset=1):
  21.     for cell in row:
  22.         print(cell.value)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement