import openpyxl
def is_chinese(string):
"""
检查整个字符串是否包含中文
:param string: 需要检查的字符串
:return: bool
"""
for ch in string:
if u'\u4e00' <= ch <= u'\u9fff':
return True
return False
type_name = 'test'
file_name_rd = type_name+'.xlsx'
wb = openpyxl.load_workbook(file_name_rd)
names = wb.sheetnames
sheet1 = wb[names[0]]
sheet2 = wb[names[1]]
sheet3 = wb[names[2]]
maxRow1 = sheet1.max_row
x = 0
str1 = []
str2 = []
indexStrm = ''
for row in sheet2['A0:M200']:
for cell in row:
cell.value = ''
for i in range(1, maxRow1+1, 1):
j = 0
for j in range(1, i, 1):
if sheet1.cell(i, 2).value == sheet1.cell(j, 2).value:
sheet1.cell(i, 1).value = '----'
break
text_tem0 = str(sheet1.cell(i, 1).value)
if 'None' != text_tem0 and '' != text_tem0 and not ('-' in text_tem0):
x += 1
strtemp = sheet1.cell(i, 1).value
strtemp = strtemp.replace('H', '')
strtemp = '0x' + strtemp
sheet2.cell(x, 1).value = strtemp
sheet2.cell(x, 2).value = sheet1.cell(i, 2).value
j = 3
j1 = 3
while j < 11:
strtemp = str(sheet1.cell(i, j1).value)
if is_chinese(strtemp):
break
else:
if not('[' in strtemp):
if '/' in strtemp:
strtemp = strtemp.replace('/', '')
sheet2.cell(x, j).value = strtemp
j += 1
else:
str1 = strtemp.split('[', 1)
strm = str1[0]
indexstrm = str1[1]
indexstrm = indexstrm.replace('[', '')
indexstrm = indexstrm.replace(']', '')
str2 = indexstrm.split(':', 1)
print(str2)
indexNum0 = int(str2[0])
indexNum1 = int(str2[1])
for k in range(0, indexNum0-indexNum1+1, 1):
sheet2.cell(x, j).value = strm + str(indexNum0-k)
testtemp = str(sheet2.cell(x, j).value)
j += 1
j1 += 1
wb.save(file_name_rd)
print('OVER1')