I need to copy the content from a table to another: And I already converted the Excel table from xls to xlsx but confused about why it raise the error and warning? is there any way to make it works with the openpyxl module?
import os, openpyxl, re
os.chdir('C:\\Users\\Administrator.PC-20170525VYEL\\Desktop')
wb = openpyxl.load_workbook('sampleTemplate - 副本.xlsx')
sheets = wb.get_sheet_by_name('A级')
wb2 = openpyxl.load_workbook('sampleTemplate.xlsx')
newsheet = wb2.get_sheet_by_name('名单导入模版')
print('...')
phoneNumRegex = re.compile(r'\d{11}')
for row in range(2, sheets.max_row + 1):
kidname = sheets['E' + str(row)].value
contact = sheets['C' + str(row)].vaule
if contact == None:
contact = 'None'
else:
contact = sheets['C' + str(row)].vaule
contactNum = sheets['D' + str(row)].value
conN = phoneNumRegex.findall(contactNum)
if len(conN) >= 2:
con1 = conN[1]
con2 = conN[2]
else:
con1 = 'None'
remark = sheet['a' + str(row)].value + ': ' + sheet['g' + str(row)].value
print('sampleTemplate.xlsx...')
newsheet['c' + str(row)] = kidname
newsheet['f' + str(row)] = contact
newsheet['h' + str(row)] = con1
newsheet['k' + str(row)] = con2
newsheet['l' + str(row)] = remark
wb2.save('newsampleTemplate.xlsx')
the output error:
Warning (from warnings module):
File "C:\Users\Administrator.PC- 20170525VYEL\AppData\Local\Programs\Python\Python36-32\lib\site- packages\openpyxl\reader\worksheet.py", line 310
warn(msg)
UserWarning: Unknown extension is not supported and will be removed
...
Traceback (most recent call last):
File "C:\Users\Administrator.PC-20170525VYEL\Desktop\Autolist.py", line 22, in <module>
contact = sheets['C' + str(row)].vaule
AttributeError: 'Cell' object has no attribute 'vaule'