[英]Python win32com convert first row to lower case
I wish to convert the first row of my excel file to lowercase. 我希望将我的excel文件的第一行转换为小写。 How do it do it: 怎么做的:
import win32com.client
excel = win32com.client.Dispatch("Excel.Application")
excel.DisplayAlerts = False
excel.Visible=False
for i in files:
doc = excel.Workbooks.Open(filepath+'/'+str(i))
ws = doc.Worksheets(str(i).split(".")[0])
ws.Rows(1).Cells.Value=lower(ws.Rows(1).Cells.Value) #This syntax is wrong
ws.Rows(1).Replace("_","")
ws.Rows(1).Replace(" ","")
doc.Save()
doc.Close()
ws.Replace()
The reason why your failed may be Cells.Value
return ((str1, str2, ... None, None, ...),)
this data type. 您失败的原因可能是Cells.Value
返回((str1, str2, ... None, None, ...),)
这种数据类型。
So try to iterate the row's cell to change value 因此,尝试迭代该行的单元格以更改值
for cell in sheet.Rows(1).Cells:
pre_value = cell.Value
if pre_value is None:
break
if type(pre_value) is str:
cell.Value = pre_value.lower()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.