from openpyxl import load_workbook
import sys

#use: python readFoamXLS.py <filename> <tagname>

if len(sys.argv) !=3:
	print "use: python readFoamXLS.py <filename> <tagname>"
	exit(-1)

wb = load_workbook(filename = sys.argv[1], use_iterators = True)

tagname=sys.argv[2]

for worksheet in wb:
    lineno=0
    for row in worksheet.iter_rows():
        validity=1
        string= "insert into FoamHalfLife values('"+tagname+"',"
        if lineno!=0:
        	cellno=0
	        for cell in row:
        	    if cell.value != None:
			if cellno<2:
	        	        string= string+str(cell.value)+','
        	    else:
        	        validity=0
		    cellno= cellno+1
        	string= string+"datetime('now'));"
        	if validity==1:
        		print string
        lineno= lineno+1
