📄 tworddoc.htm
字号:
<html>
<head>
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">
<meta name="Microsoft Border" content="none">
<title>TWordDoc</title>
</head>
<body bgcolor="#FFFFCC">
<h1 align="center"><em><font color="#800000"><b>TWordDoc</b></font></em></h1>
<p align="left"><font color="#804040"><big><strong><big><big><em>Methods</em></big></big></strong></big></font></p>
<p><tt>Constructor.CreateNewDoc(WordApp : TWordApp; Template : String);</tt> <br>
<tt>Constructor.CreateOpenDoc(WordApp : TWordApp; FileName : String); <br>
Constructor.CreateFromComDoc(WordApp : TWordApp; ComDoc : _Document);</tt><br>
<tt>Constructor.CreateFromActiveDoc(WordApp : TWordApp);</tt></p>
<blockquote>
<p>These create new TWordDoc objects. They will automatically add themselves to the
WordApp list of documents. If you are using the event sink, you should not need to create
documents from the active document as TWordApp will create TWordDocs from any documents
that are present in Word in its constructor and will also create TWordDocs from any
document that is opened in Word by the user (i.e., it will keep itself up-to-date). Also,
in this situation, CreateFromComDoc should not be needed either for the same reason (both
are used internally).</p>
</blockquote>
<p align="left"><tt>Destructor.Destroy; override;<br>
Destructor.CloseDoc(oeSaveChanges: TOleEnum);</tt></p>
<p align="left"><tt>These methods will free the TWordDoc object. The simple destructor
will not close the document in Word (so that the user can continue to edit it and save it
himself). The destructors will remove the WordDoc object from its parent WordApp list and
will also clear up any range objects associated with this document.</tt></p>
<p align="left"><tt>Print;</tt></p>
<p align="left"><tt>Rudimentary print routine. See TWordApp.PrintActiveDoc for more
information.</tt></p>
<p align="left"><tt>UpdateFields;<br>
SaveAs(Filename : String);</tt></p>
<blockquote>
<p align="left">Fairly obvious methods</p>
</blockquote>
<p align="left"><tt>UpdateFullname;</tt></p>
<blockquote>
<p align="left">The property Fullname is the name and path of the document. It is usually
kept up-do-date when the document is opened and saved. However, if the user saves the
document directly, TWordDoc will not be in sync. You can use this method to get the
current COM objects's Fullname property. When a fresh document is created it is usually
given a name like "Document1".</p>
</blockquote>
<p><tt>AddRangeFromBookMark(BookmarkName : String) : TWordRange;</tt> <br>
<tt>AddRangeFromSelection : TWordRange;</tt> <br>
<tt>AddRangeFromDoc(iStart : Integer = 1; iEnd : Integer = 1) : TWordRange;</tt> <br>
<tt>AddRangeFromRange(ComRange : Range) : TWordRange;</tt> <br>
<tt>DeleteRange(Index : Integer);</tt> </p>
<blockquote>
<p>These methods allow you to add to and delete ranges. These just call the Creator
methods of TWordRange. They should be fairly self-explanatory. AddRangeFromDoc's
parameters are measured in characters. It is really just a means of getting a TWordRange
object (esp if you omit the parameters). You can then move the range to where you want to
using TWordRange methods. AddRangeFromRange sounds a bit odd but is a means of getting a
TWordRange object from a given COM range object.</p>
</blockquote>
<tt>
<p>ReplaceBookmark (BookmarkName, ReplaceText : String; ReassignBookmark : Boolean =
True);</p>
</tt>
<blockquote>
<p>This is a quick way of replacing a bookmarked entry with text. ReassignBookmark
determines whether to reassign the new range with the original bookmark name (normally the
bookmark is lost after such a text replacement). </p>
</blockquote>
<p><tt>NoOfPages (IncludeFootnotesAndEndnotes : Boolean = False) : Integer;</tt> <br>
<tt>NoOfWords (IncludeFootnotesAndEndnotes : Boolean = False) : Integer;</tt> </p>
<blockquote>
<p>Fairly obvious functions.</p>
</blockquote>
<p><tt>GoTo_(oeWhat, oeWhich : TOleEnum; oeCount: Integer = 1; oeName: String = '') :
Range;<br>
GoToNext(oeWhat : TOleEnum) : Range;<br>
GoToPrevious(oeWhat : TOleEnum) : Range;</tt></p>
<p>These Goto... functions move the document's selection object. NB selection objects are
slow - use ranges. Also, I haven't tried moving a document's selection when it is not the
active document (I suspect you may get an exception as I think Word only has one selection
object at any one time - I may be wrong). The functions return COM range objects. You can
treat the functions as procedures and throw away the returned COM object or you could
combine these with AddRangeFromRange to get a TWordRange object.</p>
<p><font color="#804040"><strong><big><big><em><big>Properties</big></em></big></big></strong></font></p>
<p><tt>WordApp : TWordApp read FWordApp;</tt></p>
<blockquote>
<p>The parent TWordApp that owns the TWordDoc object.</p>
</blockquote>
<p><tt>Fullname : String read FFullname;</tt></p>
<blockquote>
<p>The same as the COM object Document.Fullname property. However TWordDoc stores this
internally so you don't actually need the COM object to be there to read it. This is
useful in the OnClose event where Word has already got rid of the COM document object (so
you can't get at it). You could reload the file if the user "accidentally"
closed it. Note that TWordApp and TWordDoc try to keep this up-to-date but cannot catch
all situations where the COM object's fullname has changed (e.g., if the user saves the
document himself within Word). You can use UpdateFullname to re-sync things if you suspect
this may have happened. Do not use UpdateFullname in an OnClose event (the COM object has
gone - you will get an exception).</p>
</blockquote>
<p><tt>Active : Boolean read GetActive write SetActive;</tt></p>
<blockquote>
<p>Indicates/sets whether the document is the visible active document in Word.</p>
</blockquote>
<p><tt>AutoTextEntries : OleVariant read GetAutoTextEntries;</tt></p>
<blockquote>
<p>This returns an OleVariant for you to use. For some reason the Word type library does
not go as far as providing the Document's AttachedTemplate property—it only returns
an OleVariant from the function Get_AttachedTemplate. I can think of no reason for this as
templates are defined in the type library and you can get a list of them from the
Application object. You will have to use this property as you would any late bound object.
NB this may not work if late binding is not in english with your version of Word. </p>
</blockquote>
<p><tt>Mode : TWordDocMode read FMode;</tt></p>
<blockquote>
<p>One of three things (wdmCreating, wdmExisting, wdmDestroying) to indicate whether the
object is in the middle of being created or destroyed</p>
</blockquote>
<p><tt>DocStillInWord : Boolean;</tt></p>
<blockquote>
<p>True of the TWordDoc object's COM document is still present in Word (i.e., the user
hasn't closed it behind your back). Only really a problem if you are not using the event
sink as you will get a suitable close event in that case.</p>
</blockquote>
<tt>
<p>Document : _Document;</p>
</tt>
<blockquote>
<p>This returns the actual COM _Document object.</p>
</blockquote>
<p><tt>Range [Index: Integer] : TWordRange;</tt> <br>
<tt>NoOfRanges : Integer;</tt> </p>
<blockquote>
<p>These properties allow you to retrieve ranges, usually for iterative purposes.</p>
</blockquote>
<p><tt>BookmarkByIndex [Index: Integer] : Word_TLB.Bookmark;</tt> <tt><br>
Bookmark [BookmarkName: String] : Word_TLB.Bookmark;</tt> <br>
<tt>NoOfBookmarks : Integer;</tt> </p>
<blockquote>
<p>These properties allow you to get access to the bookmark collection of the document.</p>
</blockquote>
<p><tt>ItemIndex : Integer;</tt></p>
<blockquote>
<p>Returns the index of the TWordDoc object within the TWordApp list.</p>
</blockquote>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -