Hi @ll,
nach mehr oder weniger langer Zeit hab ich mal wieder ne Frage an euch:
Ich hab ein Word-Dokument, dass unter anderem eine Tabelle enthält. Ich möchte nun mittels Python Teile diese Tabelle ausfüllen. Wie kann ich das machen?
DANKE
mfG
Tux
Word - Tabelle ausfüllen
-
- Python-Forum Veteran
- Beiträge: 16025
- Registriert: Freitag 20. Juni 2003, 16:30
- Kontaktdaten:
Über die COM Integration von win32all. Das ist aber ein etwas komplizierteres Thema, da du dadurch Word fernsteuertst. Ich kann dir mal ein Script posten, dass Wörter in Word Dokumenten ersetzt, wenn es dich interessiert.
Zuletzt geändert von Leonidas am Montag 13. Dezember 2004, 15:09, insgesamt 1-mal geändert.
My god, it's full of CARs! | Leonidasvoice vs (former) Modvoice
schaden kanns ja nicht - vielleicht kann ich mir ja da noch was raussuchen, was mir weiterhilft...
DANKE
Tux
DANKE
Tux
-
- Python-Forum Veteran
- Beiträge: 16025
- Registriert: Freitag 20. Juni 2003, 16:30
- Kontaktdaten:
Code: Alles auswählen
#!/usr/bin/env python
# -*- coding: latin-1 -*-
"""A library for writing into Word documents"""
try:
import win32com.client
except ImportError:
raise ImportError('You need the pywin32/win32all Python extensions')
def replacetext(replace, by):
"""Replaces a text by another.
Returns True if there was something replaced and False if not.
Needs _static_ dispatch"""
word = win32com.client.Dispatch('Word.Application')
sel = word.Selection
sel.Find.ClearFormatting()
sel.Find.Replacement.ClearFormatting()
sel.Find.Text = replace
sel.Find.Replacement.Text = by
sel.Find.Forward = True
sel.Find.Wrap = win32com.client.constants.wdFindContinue
sel.Find.Format = False
sel.Find.MatchCase = False
sel.Find.MatchWholeWord = False
sel.Find.MatchSoundsLike = False
sel.Find.MatchAllWordForms = False
return sel.Find.Execute(Replace=win32com.client.constants.wdReplaceAll)
My god, it's full of CARs! | Leonidasvoice vs (former) Modvoice
ich danke dir -- kennst du sonst noch irgend ne gute Seite, wos Infos über verschiedene Wordzugriffe über Python gibt?
- jens
- Python-Forum Veteran
- Beiträge: 8502
- Registriert: Dienstag 10. August 2004, 09:40
- Wohnort: duisburg
- Kontaktdaten:
Es lohnt sich immer mal wieder eine sucher hier: http://aspn.activestate.com/ASPN/Cookbook/Python/
Schau dir mal das an:
http://aspn.activestate.com/ASPN/Cookbo ... ipe/308035
http://aspn.activestate.com/ASPN/Cookbo ... ipe/279003
Schau dir mal das an:
http://aspn.activestate.com/ASPN/Cookbo ... ipe/308035
http://aspn.activestate.com/ASPN/Cookbo ... ipe/279003
-
- Python-Forum Veteran
- Beiträge: 16025
- Registriert: Freitag 20. Juni 2003, 16:30
- Kontaktdaten:
Ja das Python Cookbook ist schon nicht schlecht, das gibt's auch gedruckt von O'Reilly. O'Reilly ist ja eigentlich auch der Python Verlag
Seiten kann ich dir eigentlich nicht mehr wirklich viele zu dem Thema empfehlen, da wäre noch die Python-win32 Mailingliste und natürlich die VB MSDN Doku, die sich recht leicht auf Python übertragen lässt.
Seiten kann ich dir eigentlich nicht mehr wirklich viele zu dem Thema empfehlen, da wäre noch die Python-win32 Mailingliste und natürlich die VB MSDN Doku, die sich recht leicht auf Python übertragen lässt.
My god, it's full of CARs! | Leonidasvoice vs (former) Modvoice