各位大佬好,
不多废话,直入主题。
代码大意是把文件字符拆开,重组后,赋值让python判断,用xlwing直接写入,但运行后发现,if语句都直接跳过,文件根本没写入。提前感谢看过大佬们。
附上源代码,可能比较乱。
import xlwings as xwimport time
import os
import xlwt
import xlrd
file_dir='C:/Users/ASUS/Desktop/处理好的文件'
for root,dirs,files in os.walk(file_dir):
for a in range(0,14):
os.chdir(r'C:/Users/ASUS/Desktop/处理好的文件')
print('---------------分隔符')
print(a)
print(files[a])
app = xw.App(visible=False, add_book=False)
workbook=app.books.open(files[a])
sheets=workbook.sheets[0]
last_cell=sheets.used_range.last_cell
nrows=sheets.used_range.last_cell.row
ncols = sheets.used_range.last_cell.column
filesname=files[a]
dir0=[filesname[1],filesname[2]]
dir1=[filesname[4],filesname[5],filesname[6],filesname[7],filesname[8]]
nation=''.join(dir0)
date=''.join(dir1)
print(nation)
print(date)
print(nrows)
print(ncols)
if date==11.15:
for i in range(0,nrows):
date_value=sheets.range('i,0').value=='2021/11/15'
elif date==11.16:
for i in range(nrows):
date_value=sheets.range('i,0').value=='2021/11/16'
elif date==11.17:
for i in range(nrows):
date_value=sheets.range('i,0').value=='2021/11/17'
elif date==11.18:
for i in range(nrows):
date_value=sheets.range('i,0').value=='2021/11/18'
elif date==11.19:
for i in range(nrows):
date_value=sheets.range('i,0').value=='2021/11/19'
elif date==11.20:
for i in range(nrows):
date_value=sheets.range('i,0').value=='2021/11/20'
elif date==11.21:
for i in range(nrows):
date_value=sheets.range('i,0').value=='2021/11/21'
print('日期写入完成')
if nation=='UK':
for i in range(nrows):
nation_value=sheets[i,1].value=='Amazon.co.uk'
elif nation=='DE':
for i in range(nrows):
nation_value = sheets[i, 1].value == 'Amazon.de'
elif nation=='FR':
for i in range(nrows):
nation_value = sheets[i, 1].value == 'Amazon.fr'
elif nation=='ES':
for i in range(nrows):
nation_value = sheets[i, 1].value == 'Amazon.es'
elif nation == 'IT':
for i in range(nrows):
nation_value = sheets[i, 1].value == 'Amazon.it'
print('站点写入完成')
# for i in range(1,nrows):
#
# New_value=sheets[i,0].value=['']
workbook.close()
app.quit()
time_start = time.time()
time_end = time.time()
print('所用时间:',time_end-time_start,"秒")
time.sleep(0.1)