有关olecontainer与word控制的问题(100分)

  • 主题发起人 主题发起人 lcdjj
  • 开始时间 开始时间
L

lcdjj

Unregistered / Unconfirmed
GUEST, unregistred user!
[8D]1、用olecontainer与word融合时如何调用word的页面设置、打印对话框等对话框?
[8D]2、如何让嵌入的word支持任意位置的拖放,拖放时word的光标跟着鼠标动?
 
以前的帖子有第一个问题。
 
第二个问题:
1.开始录制一个宏,
2.拖动光标(或者移动鼠标)
3.结束宏录制。
4.到宏编辑器中看看vba代码,
5.让Delphi对相应的事件调用vba代码。
第一个问题好像不那么简单。不嫌麻烦的话,做一个自己的打印对话框(delphi带着一个)
然后再调用vba。
 
第1个问题:
OleContainer1.CreateObjectFromFile ('D:/aaa.doc', False);
OleContainer1.DoVerb (ovInPlaceActivate);
WordApplication1.ConnectTo(IDISPATCH (OleContainer1.OleObject.Application) as _Application);//用COM控制被嵌入到OleContainer中的WORD

WORD2000.pas中定义的对话框:
type
WdWordDialog = TOleEnum;
const
wdDialogHelpAbout = $00000009;
wdDialogHelpWordPerfectHelp = $0000000A;
wdDialogHelpWordPerfectHelpOptions = $000001FF;
wdDialogFormatChangeCase = $00000142;
wdDialogToolsOptionsFuzzy = $00000316;
wdDialogToolsWordCount = $000000E4;
wdDialogDocumentStatistics = $0000004E;
wdDialogFileNew = $0000004F;
wdDialogFileOpen = $00000050;
wdDialogMailMergeOpenDataSource = $00000051;
wdDialogMailMergeOpenHeaderSource = $00000052;
wdDialogMailMergeUseAddressBook = $0000030B;
wdDialogFileSaveAs = $00000054;
wdDialogFileSummaryInfo = $00000056;
wdDialogToolsTemplates = $00000057;
wdDialogOrganizer = $000000DE;
wdDialogFilePrint = $00000058;
wdDialogMailMerge = $000002A4;
wdDialogMailMergeCheck = $000002A5;
wdDialogMailMergeQueryOptions = $000002A9;
wdDialogMailMergeFindRecord = $00000239;
wdDialogMailMergeInsertIf = $00000FD1;
wdDialogMailMergeInsertNextIf = $00000FD5;
wdDialogMailMergeInsertSkipIf = $00000FD7;
wdDialogMailMergeInsertFillIn = $00000FD0;
wdDialogMailMergeInsertAsk = $00000FCF;
wdDialogMailMergeInsertSet = $00000FD6;
wdDialogMailMergeHelper = $000002A8;
wdDialogLetterWizard = $00000335;
wdDialogFilePrintSetup = $00000061;
wdDialogFileFind = $00000063;
wdDialogMailMergeCreateDataSource = $00000282;
wdDialogMailMergeCreateHeaderSource = $00000283;
wdDialogEditPasteSpecial = $0000006F;
wdDialogEditFind = $00000070;
wdDialogEditReplace = $00000075;
wdDialogEditGoToOld = $0000032B;
wdDialogEditGoTo = $00000380;
wdDialogCreateAutoText = $00000368;
wdDialogEditAutoText = $000003D9;
wdDialogEditLinks = $0000007C;
wdDialogEditObject = $0000007D;
wdDialogConvertObject = $00000188;
wdDialogTableToText = $00000080;
wdDialogTextToTable = $0000007F;
wdDialogTableInsertTable = $00000081;
wdDialogTableInsertCells = $00000082;
wdDialogTableInsertRow = $00000083;
wdDialogTableDeleteCells = $00000085;
wdDialogTableSplitCells = $00000089;
wdDialogTableFormula = $0000015C;
wdDialogTableAutoFormat = $00000233;
wdDialogTableFormatCell = $00000264;
wdDialogViewZoom = $00000241;
wdDialogNewToolbar = $0000024A;
wdDialogInsertBreak = $0000009F;
wdDialogInsertFootnote = $00000172;
wdDialogInsertSymbol = $000000A2;
wdDialogInsertPicture = $000000A3;
wdDialogInsertFile = $000000A4;
wdDialogInsertDateTime = $000000A5;
wdDialogInsertNumber = $0000032C;
wdDialogInsertField = $000000A6;
wdDialogInsertDatabase = $00000155;
wdDialogInsertMergeField = $000000A7;
wdDialogInsertBookmark = $000000A8;
wdDialogInsertHyperlink = $0000039D;
wdDialogMarkIndexEntry = $000000A9;
wdDialogMarkCitation = $000001CF;
wdDialogEditTOACategory = $00000271;
wdDialogInsertIndexAndTables = $000001D9;
wdDialogInsertIndex = $000000AA;
wdDialogInsertTableOfContents = $000000AB;
wdDialogMarkTableOfContentsEntry = $000001BA;
wdDialogInsertTableOfFigures = $000001D8;
wdDialogInsertTableOfAuthorities = $000001D7;
wdDialogInsertObject = $000000AC;
wdDialogFormatCallout = $00000262;
wdDialogDrawSnapToGrid = $00000279;
wdDialogDrawAlign = $0000027A;
wdDialogToolsEnvelopesAndLabels = $0000025F;
wdDialogToolsCreateEnvelope = $000000AD;
wdDialogToolsCreateLabels = $000001E9;
wdDialogToolsProtectDocument = $000001F7;
wdDialogToolsProtectSection = $00000242;
wdDialogToolsUnprotectDocument = $00000209;
wdDialogFormatFont = $000000AE;
wdDialogFormatParagraph = $000000AF;
wdDialogFormatSectionLayout = $000000B0;
wdDialogFormatColumns = $000000B1;
wdDialogFileDocumentLayout = $000000B2;
wdDialogFileMacPageSetup = $000002AD;
wdDialogFilePrintOneCopy = $000001BD;
wdDialogFileMacPageSetupGX = $000001BC;
wdDialogFileMacCustomPageSetupGX = $000002E1;
wdDialogFilePageSetup = $000000B2;
wdDialogFormatTabs = $000000B3;
wdDialogFormatStyle = $000000B4;
wdDialogFormatStyleGallery = $000001F9;
wdDialogFormatDefineStyleFont = $000000B5;
wdDialogFormatDefineStylePara = $000000B6;
wdDialogFormatDefineStyleTabs = $000000B7;
wdDialogFormatDefineStyleFrame = $000000B8;
wdDialogFormatDefineStyleBorders = $000000B9;
wdDialogFormatDefineStyleLang = $000000BA;
wdDialogFormatPicture = $000000BB;
wdDialogToolsLanguage = $000000BC;
wdDialogFormatBordersAndShading = $000000BD;
wdDialogFormatDrawingObject = $000003C0;
wdDialogFormatFrame = $000000BE;
wdDialogFormatDropCap = $000001E8;
wdDialogFormatBulletsAndNumbering = $00000338;
wdDialogToolsHyphenation = $000000C3;
wdDialogToolsBulletsNumbers = $000000C4;
wdDialogToolsHighlightChanges = $000000C5;
wdDialogToolsAcceptRejectChanges = $000001FA;
wdDialogToolsMergeDocuments = $000001B3;
wdDialogToolsCompareDocuments = $000000C6;
wdDialogTableSort = $000000C7;
wdDialogToolsCustomizeMenuBar = $00000267;
wdDialogToolsCustomize = $00000098;
wdDialogToolsCustomizeKeyboard = $000001B0;
wdDialogToolsCustomizeMenus = $000001B1;
wdDialogListCommands = $000002D3;
wdDialogToolsOptions = $000003CE;
wdDialogToolsOptionsGeneral = $000000CB;
wdDialogToolsAdvancedSettings = $000000CE;
wdDialogToolsOptionsCompatibility = $0000020D;
wdDialogToolsOptionsPrint = $000000D0;
wdDialogToolsOptionsSave = $000000D1;
wdDialogToolsOptionsSpellingAndGrammar = $000000D3;
wdDialogToolsSpellingAndGrammar = $0000033C;
wdDialogToolsThesaurus = $000000C2;
wdDialogToolsOptionsUserInfo = $000000D5;
wdDialogToolsOptionsAutoFormat = $000003BF;
wdDialogToolsOptionsTrackChanges = $00000182;
wdDialogToolsOptionsEdit = $000000E0;
wdDialogToolsMacro = $000000D7;
wdDialogInsertPageNumbers = $00000126;
wdDialogFormatPageNumber = $0000012A;
wdDialogNoteOptions = $00000175;
wdDialogCopyFile = $0000012C;
wdDialogFormatAddrFonts = $00000067;
wdDialogFormatRetAddrFonts = $000000DD;
wdDialogToolsOptionsFileLocations = $000000E1;
wdDialogToolsCreateDirectory = $00000341;
wdDialogUpdateTOC = $0000014B;
wdDialogInsertFormField = $000001E3;
wdDialogFormFieldOptions = $00000161;
wdDialogInsertCaption = $00000165;
wdDialogInsertAutoCaption = $00000167;
wdDialogInsertAddCaption = $00000192;
wdDialogInsertCaptionNumbering = $00000166;
wdDialogInsertCrossReference = $0000016F;
wdDialogToolsManageFields = $00000277;
wdDialogToolsAutoManager = $00000393;
wdDialogToolsAutoCorrect = $0000017A;
wdDialogToolsAutoCorrectExceptions = $000002FA;
wdDialogConnect = $000001A4;
wdDialogToolsOptionsBidi = $00000405;
wdDialogToolsOptionsView = $000000CC;
wdDialogInsertSubdocument = $00000247;
wdDialogFileRoutingSlip = $00000270;
wdDialogFontSubstitution = $00000245;
wdDialogEditCreatePublisher = $000002DC;
wdDialogEditSubscribeTo = $000002DD;
wdDialogEditPublishOptions = $000002DF;
wdDialogEditSubscribeOptions = $000002E0;
wdDialogToolsOptionsTypography = $000002E3;
wdDialogToolsOptionsAutoFormatAsYouType = $0000030A;
wdDialogControlRun = $000000EB;
wdDialogFileVersions = $000003B1;
wdDialogToolsAutoSummarize = $0000036A;
wdDialogFileSaveVersion = $000003EF;
wdDialogWindowActivate = $000000DC;
wdDialogToolsMacroRecord = $000000D6;
wdDialogToolsRevisions = $000000C5;
wdDialogEmailOptions = $0000035F;
wdDialogWebOptions = $00000382;
wdDialogFitText = $000003D7;
wdDialogPhoneticGuide = $000003DA;
wdDialogHorizontalInVertical = $00000488;
wdDialogTwoLinesInOne = $00000489;
wdDialogFormatEncloseCharacters = $0000048A;
wdDialogFormatTheme = $00000357;
wdDialogTCSCTranslator = $00000484;

调用页面设置只需要:
WordApplication.Application.Dialogs.Item(wdDialogFilePageSetup).Show(EmptyParam);
 
录宏,再把语法变为Delphi的语法
 
用WordDocument和WordApplication。
例:
procedure TForm1.Button1Click(Sender: TObject);
var
Template, NewTemplate, DocumentType, Visible, ItemIndex: OleVariant;
procedure setfont;
begin
WordFont1.ConnectTo(WordDocument1.Sentences.Get_Last.Font);
WordFont1.Bold := 1;
WordFont1.Italic := 1;
WordFont1.shadow := 1;
WordFont1.Size := 12;
end;
begin
try
Template := EmptyParam;
NewTemplate := True;
ItemIndex := 1;
try
Wordapplication1.Connect;
except
MessageDlg('无法连接,也许没有安装Word', mtError, [mbOk], 0);
Abort;
end;
Wordapplication1.Visible := False;
WordApplication1.Caption := 'Delphi Word';
//建立一个新文档
Template := EmptyParam;
NewTemplate := False;
WordApplication1.Documents.Add(Template, NewTemplate,DocumentType, Visible);
//建立WordDocument连接
WordDocument1.ConnectTo(WordApplication1.Documents.Item(ItemIndex));
//因为Word进行拼写检查需要很多时间,所以首先关闭检查
WordApplication1.Options.CheckSpellingAsYouType := False;
WordApplication1.Options.CheckGrammarAsYouType := False;
//将Memo1的内容拷贝到Word中
SetFont;
WordDocument1.Range.InsertAfter('Memo1的文本: '+#13+Memo1.Text+#13);
Button2.Enabled := True;
Button3.Enabled := True;
Button1.Enabled := False;
except
on E: Exception do
begin
ShowMessage(E.Message);
WordApplication1.Disconnect;
end;
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
WordDocument1.PrintOut;
end;
 
http://www.delphibbs.com/delphibbs/dispq.asp?lid=1902976

http://www.delphibbs.com/delphibbs/dispq.asp?lid=737517

去看看吧!!对你有帮助!!!
 
多人接受答案了。
 
后退
顶部