以下是我的python代码。
import pandas as pd
import numpy as np
import openpyxl
# This is the code
log = 'G:\Data\Hotels\Hotel.txt' #text file with list of hotel
file = open(log, 'r')
hotels = []
line = file.readlines()
for a in line:
hotels.append(a.rstrip('\n'))
# We'll use this list to keep track of all filepaths
filepaths = []
for hotel in hotels :
fp = "G:\\Data\\Hotels\\"+hotel+"\\"+hotel+" - Meetings\\"+hotel+"_Action_Log.xlsx"
filepaths.append(fp)
for filepath in filepaths:
wb = openpyxl.load_workbook(filename = filepath, data_only = True)
ws = wb.worksheets[1]
ws['B2'] = 'hotel'
wb.save
我的代码带有一个带有酒店列表的文本文件,并使用此列表遍历所有相关的酒店文件,然后对于所有这些酒店文件,我想将单元格B2的值更改为酒店名称。
但是,我不确定这是否是正确的方法,因为我是Python的新手并且我也收到了消息
C:\ Python34 \ python-3.4.4.amd64 \ lib \ site-packages \ openpyxl \ reader \ worksheet.py:319:UserWarning:不支持数据验证扩展,将被删除 警告(MSG)
答案 0 :(得分:0)
尝试ws['B2'].value = 'hotel'
。