cursor.execute("TRUNCATE TABLE ore") sheet = file_xls.sheet_by_index(0) #get sheet and pass it to read line if(end_check==0): end_check=start_check if(start_check==0): start_check=3 end_check=sheet.nrows index_line=start_check-1 while index_line<end_check: line=line_reader.read_line(sheet,index_line) error_check=prev_error prev_error=line_parser.parse(line,index_line,prev_error) #if "OK" data is consistent if error_check==prev_error: prev_error=db_writer.db_write_line(cursor,line,index_line,prev_error) #pass the line and its number #elif error_check=="Ignore": # print "Line ",index_line+2," has been ignored " # elif (prev_error<3): # print "\n\n --------------------------------- \n " # print "Data missing on line :", # print error_check+1," Sheet :",sheet.name # prev_error=prev_error+1 #else: # prev_error=prev_error+1 index_line+=1 cursor.execute("TRUNCATE TABLE ore") print "\n Only first 5 errors are displayed (if any) !!! " print " There have been found a total of",prev_error,"errors in the .xls file or in the database"
# for each sheet ot the file get all line # ################################################ index_line=2 #get sheet and pass it to read line sheet = file_xls.sheet_by_index(0) while index_line<sheet.nrows: print index_line," -------------->" line=line_reader.read_line(sheet,index_line) error_check=line_parser.parse(line,index_line) #if "OK" data is consistent if error_check=="Ok": print "Line ",index_line+2," is candidate to be inserted into DB" db_writer.db_write_line(cursor,line,index_line) #pass the line and its number elif error_check=="Ignore": print "Line ",index_line+2," has been ignored >>> " else: print "Data missing on line :", print error_check+1," Sheet :",sheet.name print "Please correct XLS file" #index_sheet=file_xls.nsheets #break index_line+=1 #test read first line in xls file -> uncomment next line to test #print "Line 0 : ",reader.read_line(xls_file,0,0) print " \n\n\n\n\n\n" print " ------------------------------------------> " print " Database ore "