win32com.client操作excel问题
我有一个类文件,文件名保存为myeasyexcel.py
from win32com.client import Dispatch
import win32com.client
class EasyExcel:
"""A utility to make it easier to get at Excel. Remembering
to save the data is your problem, as is error handling.
Operates on one workbook at a time."""
def __init__(self, filename=None): #打开文件或者新建workbook(如果不存在的话)
self.xlApp = win32com.client.Dispatch('Excel.Application')
if filename:
self.filename = filename
self.xlBook = self.xlApp.Workbooks.Open(filename)
else:
self.xlBook = self.xlApp.Workbooks.Add()
self.filename = ''
然后在另外一个py文件中引入这个类文件,但是执行后最后提示ws=wb.Worksheets(selected_name)中Worksheets方法不存在,AttributeError: 'EasyExcel' object has no attribute 'Worksheets'
Worksheets是win32com.client中的方法,怎么就不支持了?
def deleteROW():
import myeasyexcel
wb=myeasyexcel.EasyExcel(filename=os.path.join(os.getcwd(),'test.xlsx'))
ws=wb.Worksheets(selected_name)
max_row=ws.UsedRange.Rows.Count
max_col=ws.UsedRange.Column.Count
print(max_row,max_col)