Code: Alles auswählen
#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
import win32com
import win32com.client
import os
import os.path
filename = os.path.abspath("dokument.doc")
# Word-Application referenzieren
app = win32com.client.Dispatch("Word.Application")
# Word sichtbar machen. Kann später weggelassen werden
app.Visible = False
# Quelldatei öffnen
doc = app.Documents.Open(filename)
doc.Content.Font.Name = 'Times New Roman'
doc.Content.Font.Size = 14
doc.Content.Text = "Test\n"
doc.Content.Text += "Noch ein test"
doc.Content.Font.Name = 'Arial Black'
doc.Content.Font.Size = 20
doc.Content.Text += "init 6 - reboot"
hw=doc.Shapes
hw.AddPicture('Schule.bmp') # <- Das klappt nicht
doc.Bookmarks("Kontrollkästchen2").Select # <- Das klappt nicht
doc.Bookmarks("marke2").Range.InsertAfter("Hier ist Marke2") # <- Das klappt nicht
doc.Bookmarks("marke3").Range.InsertAfter("Hier ist Marke3")# <- Das klappt nicht
app.Run('Makro1')# <- Das klappt nicht
doc.Save()
try:
doc.PrintOut(True, False, 0)
except:
print "Bitte einen Drucker anschließen!"
while doc.BackgroundPrintingStatus > 0: # <- Das klappt nicht
time.sleep(0.1)
doc.Close()
del doc
app.Quit()
del app
print "Fertig"
1. Wie kann ich Checkboxen einbauen?
Wenn ich das noch dazu dichte
Code: Alles auswählen
doc.Bookmarks("Kontrollkästchen2").Select
doc.Bookmarks("marke2").Range.InsertAfter("Hier ist Marke2")
doc.Bookmarks("marke3").Range.InsertAfter("Hier ist Marke3")
app.Run('Makro1')
Code: Alles auswählen
Traceback (most recent call last):
File "C:\Dokumente und Einstellungen\Renate\Desktop\word.py", line 29, in <module>
doc.Bookmarks("Kontrollkästchen2").Select
File "C:\Python25\Lib\site-packages\win32com\client\dynamic.py", line 172, in __call__
return self._get_good_object_(self._oleobj_.Invoke(*allArgs),self._olerepr_.defaultDispatchName,None)
com_error: (-2147352567, 'Ausnahmefehler aufgetreten.', (0, u'Microsoft Word', u'Das angeforderte Element ist nicht in der Sammlung vorhanden.', u'C:\\Programme\\Microsoft Office\\Office\\1031\\wdmain9.chm', 25421, -2146822347), None)
So dass Hallo in Times New Roman geschrieben ist und Welt in IMPACT oder so.
3. Wie kann ich Text farbig machen?
4. Warum funktioniert soviel nicht?
Ich benutze Word 2003 - Vielleicht liegt das daran?