Python论坛  - 讨论区

标题:[python-chinese] 用win32com操作excel失败

2007年07月01日 星期日 20:52

Lee DYER lee.dyer在gmail.com
星期日 七月 1 20:52:20 HKT 2007

ÔÚ³õʼ»¯µÄʱºò¾Í·¢Éú´íÎ󣬱¨attribute error£¬Ã»¿´³ö´íÔÚÄÄÀÇë´ó¼ÒÖ¸µã
Ô´´úÂëÈçÏ£º


#coding=utf-8
from win32com.client import Dispatch

class ExcelCls(object):
    def __init__(self):
        self.objexcel=Dispatch('Excel.Application')
        self.excelbooks=self.objexcel.Workbooks.Add()
        self.worksheet=self.excelbooks.Worksheets(1)
        self.currentrow=1


    def WriteCell(self,x,y,value):
        self.worksheet.Cells(x,y).Value=value

    def Close(self):
        self.excelbooks.Close(SaveChanges=True)
        self.objexcel.Quit()
        del self.objexcel
        del self.excelbooks

if __name__=='__main__':
    obj=ExcelCls()
    obj.WriteCell(1,1,'µ¥Î»£º')
    obj.Close()
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070701/1cb896b3/attachment.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年07月01日 星期日 23:08

L.J lujiacn在163.com
星期日 七月 1 23:08:35 HKT 2007

我运行没有问题!
不过需要该成u'单位:',要不存的是乱码

obj.WriteCell(1,1,u'单位:')
Lee DYER wrote:
> 在初始化的时候就发生错误,报attribute error,没看出错在哪里,请大家指点
> 源代码如下:
>  
> 
> #coding=utf-8
> from win32com.client import Dispatch
> 
> class ExcelCls(object):
>     def __init__(self):       
>         self.objexcel=Dispatch('Excel.Application')       
>         self.excelbooks=self.objexcel.Workbooks.Add()
>         self.worksheet=self.excelbooks.Worksheets (1)
>         self.currentrow=1
>        
>            
>     def WriteCell(self,x,y,value):
>         self.worksheet.Cells(x,y).Value=value
>        
>     def Close(self):
>         self.excelbooks.Close(SaveChanges=True)
>         self.objexcel.Quit()
>         del self.objexcel
>         del self.excelbooks
>        
> if __name__=='__main__':
>     obj=ExcelCls()
>     obj.WriteCell(1,1,'单位:')
>     obj.Close()
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese


[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年07月02日 星期一 00:51

cun heise cunheise在hotmail.com
星期一 七月 2 00:51:33 HKT 2007

ÓиöpyExcelerator

>From: "L.J" <lujiacn在163.com>
>Reply-To: python-chinese在lists.python.cn
>To: python-chinese在lists.python.cn
>Subject: Re: [python-chinese] ÓÃwin32com²Ù×÷excelʧ°Ü
>Date: Sun, 01 Jul 2007 23:08:35 +0800
>
>我运行没有问é¢?
>不过需要该成u'单位ï¼?,要不存的是乱码
>
>obj.WriteCell(1,1,u'单位ï¼?)
>Lee DYER wrote:
> > 在初始化的时候就发生错误,报attribute error,没看出é”
™åœ¨å“ªé‡Œï¼Œè¯·å¤§å®¶æŒ‡ç‚¹
> > 源代码如下:
> >
> >
> > #coding=utf-8
> > from win32com.client import Dispatch
> >
> > class ExcelCls(object):
> >     def __init__(self):
> >         self.objexcel=Dispatch('Excel.Application')
> >         self.excelbooks=self.objexcel.Workbooks.Add()
> >         self.worksheet=self.excelbooks.Worksheets (1)
> >         self.currentrow=1
> >
> >
> >     def WriteCell(self,x,y,value):
> >         self.worksheet.Cells(x,y).Value=value
> >
> >     def Close(self):
> >         self.excelbooks.Close(SaveChanges=True)
> >         self.objexcel.Quit()
> >         del self.objexcel
> >         del self.excelbooks
> >
> > if __name__=='__main__':
> >     obj=ExcelCls()
> >     obj.WriteCell(1,1,'单位ï¼?)
> >     obj.Close()
> >
> >
> > 
------------------------------------------------------------------------
> >
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese在lists.python.cn
> > Subscribe: send subscribe to python-chinese-request在lists.python.cn
> > Unsubscribe: send unsubscribe to  
python-chinese-request在lists.python.cn
> > Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>_______________________________________________
>python-chinese
>Post: send python-chinese在lists.python.cn
>Subscribe: send subscribe to python-chinese-request在lists.python.cn
>Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
>Detail Info: http://python.cn/mailman/listinfo/python-chinese

_________________________________________________________________
ÏíÓÃÊÀ½çÉÏ×î´óµÄµç×ÓÓʼþϵͳ¡ª MSN Hotmail¡£ http://www.hotmail.com 


[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号