Play Chinese word with office

xiaoxiao2021-04-08  406

Word software is still quite good, the most intuitive feeling is that when the user edits a DOC document, Word will continue to detect its spelling error (including English words and Chinese words); not only, you may pay attention When you double-click a word in the document with the mouse, the word containing this word will be automatically selected. For example, "I am Chinese" said this, when you double click on "中", the word "Chinese" will be selected (double click "country" or "people" will also have the same effect). These signs Word are supported by Chinese word, and according to the author's experience in using office2003, its word effect is quite good.

If you can call in the application

Word

The word function is not very convenient. So, the author wants to be a simple experiment, and try a small program. I naturally think

Word

middle

"

Macro

"

,as well as

"VBA"

. First click

"

Recording macro

"

, then press

Ctrl a

. I found out

Word

Some of the macro editor

VB

Code, there is

SELECTION

Objects should be representative selection, progress further explore, discovery

Selection.Words

It is what I want, it is an array of words that will be obtained after the area is selected. In addition,

SELECTION

There are also many properties and methods, such as

Selection.sentences

It is an array of all sentences.

Next

Word

Zero zero

VBA

Code transplantation

VB6.0

Go in. Basic features of this applet:

A

Box input section article, the user click the button,

B

The effect after outputting a word is output, and all words are separated from spaces.

VB

code show as below:

Option Explicitdim WDAPP AS Word.ApplicationDim Doc as Word.Document

Private submmand1_click () 'on Error Resume Next Dim Segwords As String

Me.command1.caption = "

Be executing

... "me.command1.enabled = false segwords =" "wdapp.selection.Homekey unit: = wdstory wdapp.selection.typetext me.text1.text wdapp.selection.Wholestory Dim i as integer for i = 1 to WDAPP. Selection.Words.count segwords = segwords wdapp.selection.words (i) "" DOEvents next I wdapp.selection.delete Unit: = WDCharacter, count: = 1

Me.command1.caption = "

start testing

"Me.command1.enabled = true me.text2.text = segwordsend SUB

Private Sub Form_Load () Set wdapp = New Word.Application Set doc = wdapp.Documents.Add wdapp.ActiveDocument.SaveAs "c: //~ftemp.doc" End SubPrivate Sub Form_Terminate () doc.Close Set doc = Nothing wdapp. Quit SaveChanges: = false set wdapp = nothingend sub

The effect of the program run is as follows:

The word effect seems to be still not bad, but when the author tested with a longer article, the speed is very slow, and

ICTCLAS

The word is not in one level. I thought it was

VB

Explanation execution, use

Delphi

After rewriting, the speed is improved, but the speed is still not ideal.

Delphi

code show as below:

Unit

Unit1;

Interface

Uses

Windows, Messages, Sysutils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, Comctrls, Stdctrls, Buttons, ComoBJ;

Type

TFORM1 = Class (TFORM)

Statusbar1: TSTATUSBAR;

Groupbox1: TgroupBox;

Groupbox2: tgroupbox;

Bitbtn1: tbitbtn;

Memo1: TMEMO;

Memo2: TMEMO;

Procedure formcreate (Sender: TOBJECT);

Procedure FormDestroy (Sender: TOBJECT);

Procedure Bitbtn1click (Sender: TOBJECT);

Private

{Private Declarations}

public

{Public declarations}

END;

VAR

FORM1: TFORM1;

WDAPP: VARIANT;

Doc: Variant;

IMPLEMENTATION

{$ R * .dfm}

Procedure

TFORM1.FORMCREATE (Sender: TOBJECT);

Begin

WDAPP: = CREATEOBJECT ('Word.Application');

WDAPP.Visible: = false;

Doc: = wdapp.documents.add ();

WDAPP.ActiveDocument.saves ('c: //~ftemp.doc');

end

;

Procedure

TFORM1.FORMDESTROY (Sender: TOBJECT);

Begin

Doc.close;

WDAPP.quit (SaveChanges: = false);

end

;

Procedure

TFORM1.BITBTN1CLICK (Sender: TOBJECT);

VAR

Segwords

:

Tstringlist;

WDSTORY, WDCHARACTER

: Olevariant;

i

: Integer;

Begin

WDSTORY: = 6;

WDCharacter: = 1;

Segwords: = TSTRINGLIST.CREATE;

Self.bitbtn1.caption: = '

Be executing

"

Self.bitbtn1.enable;

Wdapp.selection.homekey (WDSTORY);

Wdapp.selection.typetext (Self.Memo1.Lines.Text); wdapp.selection.wholestory;

For i: = 1 to wdapp.seection.words.count do

Begin

Segwords.Append (wdapp.selection.words.Item (i));

END;

Wdapp.seection.delete (WDCharacter, 1);

Self.bitbtn1.caption: = '

start testing

"

Self.bitbtn1.enabled: = true;

Self.Memo2.Text: = segwords.text;

end

;

end

.

转载请注明原文地址:https://www.9cbs.com/read-132856.html

New Post(0)