Need some help here guys,
this is my code:
import xlutils
import xlrd
import os
import sys
datafile = r'C:\\someexcelfileediting.xlsx'
workbook = xlrd.open_workbook(datafile)
stone = workbook.sheet_by_name(input('What is the name of the sheet you are trying to reference? ').upper())
paper = workbook.sheet_by_name(input('what sheet would you like to check? ').upper())
def check_Base():
set2 = set()
for row in range (0, paper.nrows):
for col in range(0, paper.ncols):
set2.add(paper.cell_value(row, col))
print (len(set2))
print (set2)
check_Base()
what I end up with is 79 of 91 values for the excel sheet it is iterating over and I do not understand why it is excluding the 12 entries in the file. there doesn't seem to be a pattern to the data that it is omitting its random values from different rows and columns. any help would be appreciated.
Thanks, Will
A set
is going to give you an unordered collection of unique values. If you have duplicate cells in your spreadsheet, only the first one will be added to the set, the rest will be discarded.
Based on your comments, it sounds like you're just doing some debugging, but if you really need to count the cells that you've unpacked, one option is to append
them to a list first and then convert that to a set later.
mylist = []
for row in range (0, paper.nrows):
for col in range(0, paper.ncols):
mylist.append(paper.cell_value(row, col))
print len(mylist) # 91
myset = set(mylist)
print len(myset) # 79