- Delphiartiklar, tips, forum, länksamling - 

      

START | DELPHI | LÄNKARGÄSTBOK 




 Forum

Grundkurs
  »Introduktion
  »Snabbguide
  »Komponenter
  »Händelser
  »Strängar
  »Räkna med Delphi   »Egna typer
  »Selektion
  »Iteration
  »Menyer
  »Funktioner
  »Arraystrukturer

Tips & Tricks
  »Nya tips
  »Blandat
  »Databaser
  »Filer
  »Forms
  »Grafik
  »Internet
  »Komponenter
  »Matematik
  »Multimedia
  »Objekt/ActiveX
  »Skrivare
  »Strängar
  »System
  »Mest lästa tips

Artiklar
  »Delphi och ADO
  »Bygga en DLL
  »Skapa en enkel rapport
  »Hantera registret
  »Enheter, units
  »Klassen TCanvas
  »Använd LookUp Controls

 Nya tips
 Lägg till tips
 Delphilänkar
 Gästbok

 

Ersätt text och typsnitt i en doc-fil. Kategori: Objekt/ActiveX
Inlagt: 2007-01-20
Läst: 1502
Inlagt av: Staffan Berg
Beskrivning
Med detta kodexempel kan du ersätta både text och typsnitt i en Microsoft Word-fil (*.doc).
Kod
WordApp := CreateOLEObject('Word.Application'); 
WordApp.Documents.Open(yourDocFileName); 
 
WordApp.Selection.Find.ClearFormatting; 
WordApp.Selection.Find.Text := yourStringForSearch; 
WordApp.Selection.Find.Replacement.Text := yourNewStringForReplace; 
 
WordApp.Selection.Find.Forward := True; 
WordApp.Selection.Find.MatchAllWordForms := False; 
WordApp.Selection.Find.MatchCase := Flase; 
WordApp.Selection.Find.MatchWildcards := False; 
WordApp.Selection.Find.MatchSoundsLike := False; 
WordApp.Selection.Find.MatchWholeWord := False; 
WordApp.Selection.Find.MatchFuzzy := False; 
WordApp.Selection.Find.Wrap := wdFindContinue;  
WordApp.Selection.Find.Format := False; 
 
 
WordApp.Selection.Find.Execute(Replace := wdReplaceAll) 
 
//or replace a first occur only: 
WordApp.Selection.Find.Execute(Replace := wdReplaceOne); 
 
//if you want to check if text was found then use Found method: 
if WordApp.Selection.Find.Found then 
 //do something 
 
//save a modified document 
WordApp.ActiveDocument.SaveAs(yourDocFileName); 
 
//close MS Word instance 
WordApp.ActiveDocument.Close; 
WordApp.Quit; 
WordApp := Unassigned; 
 
//All what you need is to add ActiveX, ComObj units in use-clause and declare such consts and variables: 
 
const  
 wdFindContinue = 1; 
 wdReplaceOne = 1; 
 wdReplaceAll = 2; 
 
var  
 WordApp: Variant; 
 

 
 
© Copyright 2005 - Staffan Berg
- Alla rättigheter förbehålles -