from openpyxl import load_workbook

#########################################################################################################
workbook = load_workbook(filename = "lcd真值表.xlsx")
workbook.sheetnames
name="H5"
sheet = workbook[name]

def write_value(name):
    #mode 1
    file_object=open(name+"_mode1.txt",'w')
    list_core_all=[]
    for row in sheet.iter_rows(min_row=1, max_row=8, min_col=1, max_col=50):
        list_row=[]
        for cell in row:
            hang=cell.row
            lie=cell.column
            lie_head_str=str(sheet.cell(row=1,column=lie).value)
            cell_str=str(cell.value)
            if(cell_str !='None') and hang !=1:
                file_object.write(("#define " +name+'_R_'+cell_str).ljust(20)+"("+lie_head_str+"U+R"+str(hang-2)+")\n")
                
    file_object.close()

    #mode 0
    file_object=open(name+"_mode0.txt",'w')
    list_core_all=[]
    for row in sheet.iter_rows(min_row=1, max_row=8, min_col=1, max_col=50):
        list_row=[]
        for cell in row:
            hang=cell.row
            lie=cell.column
            lie_head_str=str(sheet.cell(row=1,column=lie).value)
            cell_str=str(cell.value)
            if(cell_str !='None') and hang !=1:
                
                str1=str((int(lie_head_str)%4)*8+hang-2)
                str2=str(int(int(lie_head_str)/4))
                file_object.write(("#define " +name+'_R_'+cell_str).ljust(20)+"("+str1+"U+R"+str2+")\n")
                
    file_object.close()
print(name)   
write_value(name)
input()
name="YR"
print(name)   
write_value(name)
input()