■ 파이썬_02
[python-win32] Re: Problem with COM and MsExcel (Brunain Christophe)
Niels Steen Krogh nielssteenkrogh@hotmail.com
Wed, 02 Apr 2003 19:45:31 +0200
Previous message: [python-win32] Problem with COM and MsExcel
Next message: [python-win32] "Casting" COM objects
Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
--------------------------------------------------------------------------------
Hi!
This script might help you - use CoInitialize ..... It helped me in a
situation similar to yours.
Good luck
Niels
Cand. Polit.
Niels Steen Krogh
Solsortvej 44
2000 F.
Tlf: 3888 8613
ZiteLab / Empower your data
>From: python-win32-request@python.org
>Reply-To: python-win32@python.org
>To: python-win32@python.org
>Subject: Python-win32 digest, Vol 1 #325 - 3 msgs
>Date: Wed, 02 Apr 2003 12:00:14 -0500
>
>Send Python-win32 mailing list submissions to
> python-win32@python.org
>
>To subscribe or unsubscribe via the World Wide Web, visit
> http://mail.python.org/mailman/listinfo/python-win32
>or, via email, send a message with subject or body 'help' to
> python-win32-request@python.org
>
>You can reach the person managing the list at
> python-win32-admin@python.org
>
>When replying, please edit your Subject line so it is more specific
>than "Re: Contents of Python-win32 digest..."
>
>
>Today's Topics:
>
> 1. Re: Using py2exe with COM server question (Wolf Logan)
> 2. Re: Using py2exe with COM server question (Cory Dodt)
> 3. Problem with COM and MsExcel (Brunain Christophe)
>
>--__--__--
>
>Message: 1
>From: "Wolf Logan"
>To:
>Subject: Re: [python-win32] Using py2exe with COM server question
>Date: Tue, 1 Apr 2003 11:30:38 -0800
>
>CreateGuid() will create (in most cases) a CLSID that is unique. that means
>that no one else will ever produce that same CLSID. in that case, you can
>distribute your package with that CLSID hard-coded, and it'll work just
>fine -- it willnever collide with another CLSID.
>
>non-python objects that are distributed in other ways also use a hard-coded
>CLSID. the trick is to create a *new* CLSID when your object is revised
>sufficiently that its interface changes.
>
>----- Original Message -----
>From: "Larry Bates"
>Sent: Tuesday, April 01, 2003 7:28 AM
>
>
> > Problem:
> >
> > I'm confused about how to 'properly' handle the _reg_clsid_
> > attribute of the class. It is my understanding that this needs
> > to come from pythoncom.CreateGuid() on the machine where the COM
> > object is being installed and it is unique to that machine.
> > If this is the case, what is the best way to make this happen in
> > a 'frozen' COM object? The example shown has a hard coded GUID
> > and that just doesn't seem right for distribution to other machines.
>
>
>
>--__--__--
>
>Message: 2
>Date: Tue, 1 Apr 2003 13:15:07 -0800 (PST)
>From: Cory Dodt
>To: python-win32@python.org
>Subject: [python-win32] Re: Using py2exe with COM server question
>
> > I'm confused about how to 'properly' handle the _reg_clsid_
> > attribute of the class. It is my understanding that this needs
> > to come from pythoncom.CreateGuid() on the machine where the COM
> > object is being installed and it is unique to that machine.
>
>Guid stands for 'globally unique ID', with emphasis on the word global.
>The recipe shows the guid hard-coded because that really is the right way
>to do it. A Guid is a promise that any object with this clsid conforms to
>the same interface as every other object with that guid, on any machine,
>anywhere in the universe.
>
>It's perfectly ok to 'print pythoncom.CreateGuid()' in an interactive
>browser and paste that into your _reg_clsid_.
>
>
>__________________________________________________
>Do you Yahoo!?
>Yahoo! Tax Center - File online, calculators, forms, and more
>http://platinum.yahoo.com
>
>
>--__--__--
>
>Message: 3
>From: Brunain Christophe
>To: "Pythonwin (E-mail)"
>Date: Wed, 2 Apr 2003 08:46:03 +0200
>Subject: [python-win32] Problem with COM and MsExcel
>
>Hello all !
>
>I begin tu use python win and the COM features
>
>I try to do a little scripyt that takes a text file (an unload from a
>database) and to put it in an excel worksheet
>
>It works good, but only one time
>
>the second time I execute the script, i only se the menubar and the =
>toolbar
>on the top of the screen, the document itself is not displaying
>
>I see only what was my screen before the execution of the script
>
>If i close all the excel sheets and look in the task manager, I see an
>EXCEL.EXE still running
>
>If i make an "end process" it works, but if i try to run the script =
>once
>again, it makes an error.
>
>here is the script i use
>
>import win32com.client
>
>ex =3D win32com.client.Dispatch("Excel.Application")
>ex.Visible =3D 1
>ex.Workbooks.Open("C:\\test\\test.xls")
>ex.Run("SaveText","C:\\test\\codes", "C:\\test\\codes2.xls")
>ex.Quit
>
>and the traceback i got when i close the excel.exe and run the script =
>once
>again
>
>PythonWin 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on =
>win32.
>Portions Copyright 1994-2001 Mark Hammond (mhammond@skippinet.com.au) - =
>see
>'Help/About PythonWin' for further copyright information.
>Traceback (most recent call last):
> File
>"C:\Python22\lib\site-packages\Pythonwin\pywin\framework\scriptutils.py"=
>,
>line 307, in RunScript
> debugger.run(codeObject, __main__.__dict__, start_stepping=3D0)
> File =
>"C:\Python22\lib\site-packages\Pythonwin\pywin\debugger\__init__.py",
>line 60, in run
> _GetCurrentDebugger().run(cmd, globals,locals, start_stepping)
> File =
>"C:\Python22\lib\site-packages\Pythonwin\pywin\debugger\debugger.py",
>line 591, in run
> exec cmd in globals, locals
> File "C:\test\test1.py", line 4, in ?
> ex.Visible =3D 1
> File "C:\Python22\lib\site-packages\win32com\client\dynamic.py", line =
>504,
>in __setattr__
> raise AttributeError, "Property '%s.%s' can not be set." %
>(self._username_, attr)
>AttributeError: Property 'Excel.Application.Visible' can not be set.
>
>Does someone know what's wrong ?
>i've looked in the archives of this mailing list but i haven't found :(
>
>Thanks a lot for your answers
>
>PS :
>Sorry if my english is not so good
>
>Brunain Christophe
>Service informatique de l'expertise m=E9dicale
>SPF Sant=E9 Publique, S=E9curit=E9 de la chaine alimentaire et =
>Environnement
>
>
>
>--__--__--
>
>_______________________________________________
>Python-win32 mailing list
>Python-win32@python.org
>http://mail.python.org/mailman/listinfo/python-win32
>
>
>End of Python-win32 Digest
_________________________________________________________________
Send s?de postkort til s?de mennesker http://www.msn.dk/postkort
--------------------------------------------------------------------------------
Previous message: [python-win32] Problem with COM and MsExcel
Next message: [python-win32] "Casting" COM objects
Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
[python-win32] Re: Problem with COM and MsExcel (Brunain Christophe)
Niels Steen Krogh nielssteenkrogh@hotmail.com
Wed, 02 Apr 2003 19:45:31 +0200
Previous message: [python-win32] Problem with COM and MsExcel
Next message: [python-win32] "Casting" COM objects
Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
--------------------------------------------------------------------------------
Hi!
This script might help you - use CoInitialize ..... It helped me in a
situation similar to yours.
Good luck
Niels
from win32com.client import Dispatch from pythoncom import CoInitialize,CoUninitialize CoInitialize() #start com thread - kan udelades, men vil mindske stabiliteten o=Dispatch("Excel.Application") #start excel o.Visible=0 #excel k?rer i baggrunden o.Workbooks.Open(Filename='c:\\dokumenter\\mappe14.xls') #get the workbook o.Workbooks(1).Sheets(1).Cells.Clear() #clear the workbook sht=o.Workbooks(1).Sheets(1) #peg p? ark 1 sht.Range(sht.Cells(1,1),sht.Cells(len(data),len(data[0]))).Value=data #put a range of data (tupple formatted) o.Workbooks(1).Save() #gem regneark o.Workbooks(1).Close(SaveChanges='0') #close workbook without dialog o.Quit() #luk excel del o #slet objekt del sht #slet objekt del data #slet objekt CoUninitialize() #close com thread
Cand. Polit.
Niels Steen Krogh
Solsortvej 44
2000 F.
Tlf: 3888 8613
ZiteLab / Empower your data
>From: python-win32-request@python.org
>Reply-To: python-win32@python.org
>To: python-win32@python.org
>Subject: Python-win32 digest, Vol 1 #325 - 3 msgs
>Date: Wed, 02 Apr 2003 12:00:14 -0500
>
>Send Python-win32 mailing list submissions to
> python-win32@python.org
>
>To subscribe or unsubscribe via the World Wide Web, visit
> http://mail.python.org/mailman/listinfo/python-win32
>or, via email, send a message with subject or body 'help' to
> python-win32-request@python.org
>
>You can reach the person managing the list at
> python-win32-admin@python.org
>
>When replying, please edit your Subject line so it is more specific
>than "Re: Contents of Python-win32 digest..."
>
>
>Today's Topics:
>
> 1. Re: Using py2exe with COM server question (Wolf Logan)
> 2. Re: Using py2exe with COM server question (Cory Dodt)
> 3. Problem with COM and MsExcel (Brunain Christophe)
>
>--__--__--
>
>Message: 1
>From: "Wolf Logan"
>To:
>Subject: Re: [python-win32] Using py2exe with COM server question
>Date: Tue, 1 Apr 2003 11:30:38 -0800
>
>CreateGuid() will create (in most cases) a CLSID that is unique. that means
>that no one else will ever produce that same CLSID. in that case, you can
>distribute your package with that CLSID hard-coded, and it'll work just
>fine -- it willnever collide with another CLSID.
>
>non-python objects that are distributed in other ways also use a hard-coded
>CLSID. the trick is to create a *new* CLSID when your object is revised
>sufficiently that its interface changes.
>
>----- Original Message -----
>From: "Larry Bates"
>Sent: Tuesday, April 01, 2003 7:28 AM
>
>
> > Problem:
> >
> > I'm confused about how to 'properly' handle the _reg_clsid_
> > attribute of the class. It is my understanding that this needs
> > to come from pythoncom.CreateGuid() on the machine where the COM
> > object is being installed and it is unique to that machine.
> > If this is the case, what is the best way to make this happen in
> > a 'frozen' COM object? The example shown has a hard coded GUID
> > and that just doesn't seem right for distribution to other machines.
>
>
>
>--__--__--
>
>Message: 2
>Date: Tue, 1 Apr 2003 13:15:07 -0800 (PST)
>From: Cory Dodt
>To: python-win32@python.org
>Subject: [python-win32] Re: Using py2exe with COM server question
>
> > I'm confused about how to 'properly' handle the _reg_clsid_
> > attribute of the class. It is my understanding that this needs
> > to come from pythoncom.CreateGuid() on the machine where the COM
> > object is being installed and it is unique to that machine.
>
>Guid stands for 'globally unique ID', with emphasis on the word global.
>The recipe shows the guid hard-coded because that really is the right way
>to do it. A Guid is a promise that any object with this clsid conforms to
>the same interface as every other object with that guid, on any machine,
>anywhere in the universe.
>
>It's perfectly ok to 'print pythoncom.CreateGuid()' in an interactive
>browser and paste that into your _reg_clsid_.
>
>
>__________________________________________________
>Do you Yahoo!?
>Yahoo! Tax Center - File online, calculators, forms, and more
>http://platinum.yahoo.com
>
>
>--__--__--
>
>Message: 3
>From: Brunain Christophe
>To: "Pythonwin (E-mail)"
>Date: Wed, 2 Apr 2003 08:46:03 +0200
>Subject: [python-win32] Problem with COM and MsExcel
>
>Hello all !
>
>I begin tu use python win and the COM features
>
>I try to do a little scripyt that takes a text file (an unload from a
>database) and to put it in an excel worksheet
>
>It works good, but only one time
>
>the second time I execute the script, i only se the menubar and the =
>toolbar
>on the top of the screen, the document itself is not displaying
>
>I see only what was my screen before the execution of the script
>
>If i close all the excel sheets and look in the task manager, I see an
>EXCEL.EXE still running
>
>If i make an "end process" it works, but if i try to run the script =
>once
>again, it makes an error.
>
>here is the script i use
>
>import win32com.client
>
>ex =3D win32com.client.Dispatch("Excel.Application")
>ex.Visible =3D 1
>ex.Workbooks.Open("C:\\test\\test.xls")
>ex.Run("SaveText","C:\\test\\codes", "C:\\test\\codes2.xls")
>ex.Quit
>
>and the traceback i got when i close the excel.exe and run the script =
>once
>again
>
>PythonWin 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on =
>win32.
>Portions Copyright 1994-2001 Mark Hammond (mhammond@skippinet.com.au) - =
>see
>'Help/About PythonWin' for further copyright information.
>Traceback (most recent call last):
> File
>"C:\Python22\lib\site-packages\Pythonwin\pywin\framework\scriptutils.py"=
>,
>line 307, in RunScript
> debugger.run(codeObject, __main__.__dict__, start_stepping=3D0)
> File =
>"C:\Python22\lib\site-packages\Pythonwin\pywin\debugger\__init__.py",
>line 60, in run
> _GetCurrentDebugger().run(cmd, globals,locals, start_stepping)
> File =
>"C:\Python22\lib\site-packages\Pythonwin\pywin\debugger\debugger.py",
>line 591, in run
> exec cmd in globals, locals
> File "C:\test\test1.py", line 4, in ?
> ex.Visible =3D 1
> File "C:\Python22\lib\site-packages\win32com\client\dynamic.py", line =
>504,
>in __setattr__
> raise AttributeError, "Property '%s.%s' can not be set." %
>(self._username_, attr)
>AttributeError: Property 'Excel.Application.Visible' can not be set.
>
>Does someone know what's wrong ?
>i've looked in the archives of this mailing list but i haven't found :(
>
>Thanks a lot for your answers
>
>PS :
>Sorry if my english is not so good
>
>Brunain Christophe
>Service informatique de l'expertise m=E9dicale
>SPF Sant=E9 Publique, S=E9curit=E9 de la chaine alimentaire et =
>Environnement
>
>
>
>--__--__--
>
>_______________________________________________
>Python-win32 mailing list
>Python-win32@python.org
>http://mail.python.org/mailman/listinfo/python-win32
>
>
>End of Python-win32 Digest
_________________________________________________________________
Send s?de postkort til s?de mennesker http://www.msn.dk/postkort
--------------------------------------------------------------------------------
Previous message: [python-win32] Problem with COM and MsExcel
Next message: [python-win32] "Casting" COM objects
Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
댓글
댓글 쓰기