我正在尝试使用“填充系列”自动填充,将两个工作表上的单元格A11的值格式化为A12。这需要使用win32com模块来实现。我的代码是:
from win32com.client import Dispatch
from win32com.client import constants
xl = Dispatch('Excel.Application')
xl.Visible = True
wb = xl.Workbooks.Open ('S:\\Height Peak.xls')
ws = wb.Worksheets(['Sheet1','Sheet2'])
ws.Select()
ws.Range('A10:A11').AutoFill(ws.Range('A11:A12'), xlFillSeries)
运行代码后,立即遇到以下错误:
AttributeError:未知范围
答案 0 :(得分:1)
有3个问题:
代码:
from win32com.client import Dispatch
from win32com.client import constants as const
xl = Dispatch('Excel.Application')
xl.Visible = True
wb = xl.Workbooks.Open ('S:\\Height Peak.xls')
ws = wb.Worksheets
for sheet in ws:
if sheet.Name.endswith("1") or sheet.Name.endswith("2"):
sourceRange = sheet.Range('A1:A10')
fillRange = sheet.Range('A1:A12')
sourceRange.AutoFill(fillRange, const.xlFillSeries)