qq_24639739 2015-11-17 10:43 采纳率: 0%
浏览 4869

python win32com对EXCEL操作中的问题

定义了一个类
class easyExcel:

def __init__(self, filename=None):
    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 = ''

def save(self, newfilename=None):
    if newfilename:
        self.filename = newfilename
        self.xlBook.SaveAs(newfilename)
    else:
        self.xlBook.Save()

def close(self):
    self.xlBook.Close(SaveChanges=0)
    del self.xlApp

def getCell(self, sheet, row, col):
    sht = self.xlBook.Worksheets(sheet)
    return sht.Cells(row, col).Value

def setCell(self, sheet, row, col, value):
    sht = self.xlBook.Worksheets(sheet)
    sht.Cells(row, col).Value= value

def getRange(self, sheet, row1, col1, row2, col2):
    sht = self.xlBook.Worksheets(sheet)
    return sht.Range(sht.Cells(row1, col1), sht.Cells(row2, col2)).Value

def addPicture(self, sheet, pictureName, Left, Top, Width, Height):
    sht = self.xlBook.Worksheets(sheet)
    sht.Shapes.AddPicture(pictureName, 1, 1, Left, Top, Width, Height)

def cpSheet(self, before):
    shts = self.xlBook.Worksheets
    shts(1).Copy(None,shts(1))

使用其中的setCell函数
lhwexcele.setCell('sheet1',0,0,'xkmc')
总是会提示
AttributeError: 'NoneType' object has no attribute 'Value'

  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2022-09-09 18:34
    关注
    不知道你这个问题是否已经解决, 如果还没有解决的话:

    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 以帮助更多的人 ^-^
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算