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)
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)
...全文
相关推荐
解决python中导入win32com.client出错的问题
准备写一个操作Excel脚本却在导入包的时候出现了一个小问题 导入包 from Tkinter import Tk from time import sleep, ctime from tkMessageBox import showwarning from urllib import urlopen import win32com.client as win32 报错提示 Traceback (most recent call last): File estock.pyw, line 7, in import win32com.client as win32 I
python win32 excel python win32 excel
python win32 excel python win32 excel
python使用win32com操作office文件
python使用win32com操作office文件
python用win32com处理excel表格.pdf
python用win32com处理excel表格.pdf
python Excel win32 com
python Excel win32 com



