C打開Word文檔詳解_第1頁(yè)
C打開Word文檔詳解_第2頁(yè)
C打開Word文檔詳解_第3頁(yè)
C打開Word文檔詳解_第4頁(yè)
C打開Word文檔詳解_第5頁(yè)
已閱讀5頁(yè),還剩47頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

C#操作WordWord對(duì)象模型圖Application:用來(lái)表現(xiàn)WORD應(yīng)用程序,包含其它所有對(duì)象。他的成員經(jīng)常應(yīng)用于整個(gè)Word,可以用它的屬性和方法控制Word環(huán)境。Document對(duì)象:Document對(duì)象是Word編程的核心。當(dāng)打開一個(gè)已有的文檔或創(chuàng)建一個(gè)新的文檔時(shí),就創(chuàng)建了一個(gè)新的Document對(duì)象,新創(chuàng)建的Document將會(huì)被添加到WordDocumentsCollection。Selection:Selection對(duì)象是描述當(dāng)前選中的區(qū)域。若選擇區(qū)域?yàn)榭?,則認(rèn)為是當(dāng)前光標(biāo)處。Rang:是Document的連續(xù)部分,根據(jù)起始字符的結(jié)束字符定議位置。Bookmark:類似于Rang,但Bookmark可以有名字并在保存Document時(shí)Bookmark也被保存。以下代碼則為打開一個(gè)WORD2003文件:publicvoidCreateWordDocument(stringFileName){if(FileName==””)return;this.thisApplication=newMicrosoft.Office.Interop.Word.ApplicationClass();thisApplication.Cation=””;thisApplication.Visible=true;thisApplication.Options.CheckSpellingAsYouType=false;thisApplication.Options.CheckGrammarAsYouType=false;Objectfilename=FileName;ObjectConfirmConversions=false;ObjectReadOnly=false;ObjectAddToRecentFiles=false;ObjectPasswordDocument=System.Type.Missing;ObjectPasswordTemplate=System.Type.Missing;ObjectRevert=System.Type.Missing;ObjectWritePasswordDocument=System.Type.Missing;ObjectWritePasswordTemplate=System.Type.Missing;ObjectFormat=System.Type.Missing;ObjectEncoding=System.Type.Missing;ObjectVisible=System.Type.Missing;ObjectOpenAndRepair=System.Type.Missing;ObjectDocumentDirection=System.Type.Missing;ObjectNoEncodingDialog=System.Type.Missing;ObjectXMLTransform=System.Type.Missing;//

Microsoft.Office.Interop.Word.DocumentClasswordDoc=

//

wordApp.Documents.Open(reffilename,refConfirmConversions,

//

refReadOnly,refAddToRecentFiles,refPasswordDocument,refPasswordTemplate,

//

refRevert,refWritePasswordDocument,refWritePasswordTemplate,refFormat,

//

refEncoding,refVisible);

//

Microsoft.Office.Interop.Word.DocumentClasswordDoc=

//

wordApp.Documents.Open(reffilename,refConfirmConversions,refReadOnly,ref//AddToRecentFiles,refPasswordDocument,refPasswordTemplate,refRevert,ref//WritePasswordDocument,refWritePasswordTemplate,refFormat,refEncoding,ref//Visible,refOpenAndRepair,refDocumentDirection,refNoEncodingDialog);

Microsoft.Office.Interop.Word.DocumentwordDoc=

thisApplication.Documents.Open(reffilename,refConfirmConversions,

refReadOnly,refAddToRecentFiles,refPasswordDocument,refPasswordTemplate,

refRevert,refWritePasswordDocument,refWritePasswordTemplate,refFormat,

refEncoding,refVisible,refOpenAndRepair,refDocumentDirection,

refNoEncodingDialog,refXMLTransform);

this.thisDocument=wordDoc;

formFields=wordDoc.FormFields;

}}關(guān)閉WORD程序:ObjectSaveChangs=false;ObjectOriginalFormat=System.Type.Missing;ObjectRouteDocument=System.Type.Missing;this.thisApplication.Quit(refSaveChanges,refOriginalFormat,refRouteDocument);一個(gè)Document可能會(huì)有多個(gè)Rang對(duì)象。Rang由起始和結(jié)束字符來(lái)定它的位置。以下代碼為先清空Document里的內(nèi)容,再在第一行寫入內(nèi)容://ClearoutanyexistinginformationObjectstart=Type.Missing;Objectend=Type.Missing;Objectunit=Type.Missing;Objectcount=Type.Missing;ThisDocument.Range(refstart,refend).Delete(refunit,refcount);//SetuptheheaderinformationStart=0;End=0;rng=ThisDocument.Range(refstart,refend);rng.InsertBefore(“Xiaopai”);rng.Font.Name=”Verdana”;rng.Font.Size=16;rng.InsertParagraphAfter();//輸入回車以下為在剛寫入的內(nèi)容后添加一個(gè)表格:ObjectmissingValue=Type.Missing;Objectlocation=8;//注:若location超過(guò)已有字符的長(zhǎng)度將會(huì)出錯(cuò)Word.Rangerng=ThisDocument.Range(reflocation,reflocation);ThisDocument.Tables.Add(rng,3,4,refmissingValue,refmissingValue);以下為在剛創(chuàng)建的表格里添加一行:Word.Tabletbl=ThisDocument.Tables[1];//第一個(gè)表格為1,而不是0ObjectbeforeRow=Type.Missing;tbl.Rows.Add(refbeforeRow);//在表格的最后添加一行填充表格內(nèi)容:tbl.Cell(1,1).Range.Text=”shuai”;//在表格的第一行第一列填入內(nèi)容設(shè)置單元格風(fēng)格:Word.RangerngCell;rngCell=tbl.Cell(1,2).Range;rngCell.ParagraphFormat.Alignment=Word.WdParagraphAlignment.wdAlignParagraphRight;rngCell.FontSize=8;rngCell.Font.Name=”Verdana”;C#編程實(shí)現(xiàn)在Word文檔中搜索文本W(wǎng)ord的對(duì)象模型有比較詳細(xì)的幫助文檔,放在Office安裝程序目錄,office2003是在ProgramFiles\MicrosoftOffice\OFFICE11\2052下,文檔本身是VBA提供的,在這個(gè)目錄下還可以看到所有的office應(yīng)用程序的VBA幫助。打開VBAWD10.CHM,看到word的對(duì)象模型,根據(jù)以往的使用經(jīng)驗(yàn),很容易在Document對(duì)象下找到Content屬性,該屬性會(huì)返回一個(gè)文檔文字部分的Range對(duì)象,從這個(gè)對(duì)象中不難取所有文檔內(nèi)容,再用string的IndexOf()方法很容易達(dá)到目標(biāo)。objectfilename=”…”;//要打開的文檔路徑stringstrKey=”…”;//要搜索的文本objectMissingValue=Type.Missing;Word.Applicationwp=newWord.ApplicationClass();Word.Documentwd=wp.Documents.Open(reffilename,refMissingValue,refMissingValue,refMissingValue,refMissingValue,refMissingValue,refMissingValue,refMissingValue,refMissingValue,refMissingValue,refMissingValue,refMissingValue,refMissingValue,refMissingValue,refMissingValue,refMissingValue);if(wd.Context.Text.IndexOf(strKey)>=0){MessageBox.Show(“文檔中包含指定的關(guān)鍵字!”,”搜索結(jié)果”,MessageBoxButtons.OK);}else{MessageBox.Show(“文檔中沒(méi)有指定的關(guān)鍵字!”,”搜索結(jié)果”,MessageBoxButton.OK);}不過(guò),這種做法很勉強(qiáng)的,對(duì)小文檔來(lái)說(shuō),不存在問(wèn)題,對(duì)超長(zhǎng)超大的文檔來(lái)說(shuō),這樣實(shí)現(xiàn)方法已經(jīng)暗埋bug了,而且是程序級(jí)的bug,因?yàn)檎5臏y(cè)試會(huì)很難發(fā)現(xiàn)問(wèn)題,在使用中導(dǎo)致程序出現(xiàn)什么樣的結(jié)果也很難量化描述。其實(shí),在Word中已經(jīng)提供了可以用作搜索的對(duì)象Find,在對(duì)象模型上也比較容易找到,對(duì)應(yīng)的說(shuō)明是這樣的:該對(duì)象代表查找操作的執(zhí)行條件。Find對(duì)象的屬性和方法與“替換”對(duì)話框中的選項(xiàng)一致。從模型上看,F(xiàn)ind對(duì)象是Selection的成員,從示例代碼來(lái)看似乎也是Range的成員,查找Range的屬性,果然如此。修改代碼如下:wd.Content.Find.Text=strKey;if(wd.Content.Find.Execute(refMissingValue,refMissingValue,refMissingValue,refMissingValue,refMissingValue,refMissingValue,refMissingValue,refMissingValue,refMissingValue,refMissingValue,refMissingValue,refMissingValue,refMissingValue,refMissingValue,refMissingValue)){MessageBox.Show(“文檔中包含指定的關(guān)鍵字!”,”搜索結(jié)果”,MessageBoxButtons.OK);}else{MessageBox.Show(“文檔中沒(méi)有指定的關(guān)鍵字!”,”搜索結(jié)果”,MessageBoxButton.OK);}這樣似乎也不是最好,因?yàn)橹灰袛嘀付ǖ奈谋臼遣皇窃谖臋n中,而不需要知道它出現(xiàn)了幾次,如果有多個(gè)要搜索的文本,不可能每次都進(jìn)行全文檔搜索。假設(shè)要搜索的文本包含在文檔中,最好的情況是在文檔開頭就包含要查找的文本,最壞的情況是在文檔的最后包含要查找的文本,如果每次取一部分文檔進(jìn)行判斷,符合條件就結(jié)束本次搜索,就可以避免每次搜索整文檔了。模型中的Paragraphs對(duì)象現(xiàn)在派上用場(chǎng)了,再修改代碼如下:…Inti=0,iCount=0;Word.Findwfnd;if(wd.Paragraphs!=null&&wd.Paragraphs.Count>0){iCount=wd.Paragraphs.Count;for(i=1;i<iCount;i++){wfnd=wd.Paragraphs[i].Range.Find;wfnd.ClearFormatting();wfnd.Text=strKey;if(wfnd.Execute(refMissingValue,refMissingValue,refMissingValue,refMissingValue,wfnd.Execute(refMissingValue,refMissingValue,refMissingValue,refMissingValue,wfnd.Execute(refMissingValue,refMissingValue,refMissingValue,refMissingValue,wfnd.Execute(refMissingValue,refMissingValue,refMissingValue)){MessageBox.Show(“文檔中包含指定的關(guān)鍵字!”,”搜索結(jié)果”,MessageBoxButtons.OK);}}}對(duì)word文檔編程,以及從模板文檔批量生成新的word文檔還是在幫hr作文檔批量生成系統(tǒng)的時(shí)候,需要對(duì)word文檔編程,并且要根據(jù)模板批量生成新的文檔。參考microsoftoffice2003幫助文件之后知道了,office本身提供了編程類庫(kù),在office11文件夾低下的msword.olb。在.net開發(fā)環(huán)境中新建一個(gè)project,引入此類庫(kù),便能很方便的對(duì)word文檔編程。留下實(shí)例代碼,以便后用和他用:usingSystem;namespaceTestGrid

{

///<summary>

///SummarydescriptionforEmployee.

///</summary>

publicclassEmployee

{

///<summary>

///Initializesannewinstanceof<seecref="Employee"/>class.

///</summary>

publicEmployee()

{

}

///<summary>

///Initializesannewinstanceof<seecref="Employee"/>class.

///</summary>

///<paramname="lastName">Thelastname.</param>

///<paramname="position">Theposition.</param>

///<paramname="salary">Thesalary.</param>

publicEmployee(stringlastName,stringposition,stringsalary)

{

this.m_lastName=lastName;

this.m_position=position;

this.m_salary=salary;

}

///<summary>

///Privatefieldofthe<seecref="LastName"/>property.

///</summary>

privatestringm_lastName;

///<summary>

///Privatefieldofthe<seecref="Position"/>property.

///</summary>

privatestringm_position;

///<summary>

///Privatefieldofthe<seecref="Salary"/>property.

///</summary>

privatestringm_salary;

///<summary>

///Getsorsetsthelastname.

///</summary>

///<value>Thelastname.</value>

///<exceptioncref="ArgumentNullException">

///Throwswhilethevalueis<seelangword="null"/>.

///</exception>

///<exceptioncref="ArgumentNullException">

///Throwswhilethevalueisanemptystring.

///</exception>

publicstringLastName

{

get

{

returnthis.m_lastName;

}

set

{

if(value==null)

thrownewArgumentNullException("lastName");

if(value.Length==0)

thrownewArgumentNullException("lastName");

this.m_lastName=value;

}

}

///<summary>

///Getsorsetstheposition.

///</summary>

///<value>Theposition.</value>

///<exceptioncref="ArgumentNullException">

///Throwswhilethevalueis<seelangword="null"/>.

///</exception>

///<exceptioncref="ArgumentNullException">

///Throwswhilethevalueisanemptystring.

///</exception>

publicstringPosition

{

get

{

returnthis.m_position;

}

set

{

if(value==null)

thrownewArgumentNullException("position");

if(value.Length==0)

thrownewArgumentNullException("position");

this.m_position=value;

}

}

///<summary>

///Getsorsetsthesalary.

///</summary>

///<value>Thesalary.</value>

///<exceptioncref="ArgumentNullException">

///Throwswhilethevalueis<seelangword="null"/>.

///</exception>

///<exceptioncref="ArgumentNullException">

///Throwswhilethevalueisanemptystring.

///</exception>

publicstringSalary

{

get

{

returnthis.m_salary;

}

set

{

if(value==null)

thrownewArgumentNullException("salary");

if(value.Length==0)

thrownewArgumentNullException("salary");

this.m_salary=value;

}

}

}

}usingSystem;

usingMicrosoft.Office.Core;

usingMicrosoft.Office.Interop;namespaceTestGrid

{

///<summary>

///SummarydescriptionforWordOperation.

///</summary>

publicclassWordOperation

{

publicWordOperation()

{

}

///<summary>

///Generatesworddocumentswiththeinformationofemployees.

///</summary>

///<paramname="employees">Asetofemployee.</param>

publicstaticvoidGenerateWordDocument(Employee[]employees)

{

Microsoft.Office.Interop.Word.ApplicationwordApplication=newMicrosoft.Office.Interop.Word.ApplicationClass();

wordApplication.Visible=false;

ObjectmissingValue=Type.Missing;

ObjectstrFileName=@"D:\offer.doc";

Microsoft.Office.Interop.Word.DocumenttempDocument=null;

Objectforward=true;

ObjectstrFindName=@"#@name@#";//Thestringtobereplaced.

ObjectstrFindSalary=@"#@salary@#";//Thestringtobereplaced.

ObjectstrFindPosition=@"#@position@#";//Thestringtobereplaced.

ObjectstrReplaceName;

ObjectstrReplacePosition;

ObjectstrReplaceSalary;

foreach(Employeeemployeeinemployees)

{

strReplaceName=employee.LastName;

strReplacePosition=employee.Position;

strReplaceSalary=employee.Salary;

//Openandsavethetemplatefileasanothername.

ObjectstrSaveAsName="d:\\"+(string)strReplaceName+".doc";

Microsoft.Office.Interop.Word.DocumentwordDocument=wordApplication.Documents.Open(

refstrFileName,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue);

wordDocument.SaveAs(

refstrSaveAsName,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue);

wordDocument.Close(refmissingValue,refmissingValue,refmissingValue);

//Openthenewfile.

tempDocument=wordApplication.Documents.Open(

refstrSaveAsName,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue);

//Replacesname.

tempDocument.Content.Find.Replacement.ClearFormatting();

tempDocument.Content.Find.Wrap=Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue;

tempDocument.Content.Find.Execute(

refstrFindName,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refforward,

refmissingValue,

refmissingValue,

refstrReplaceName,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue);

//Remplacesposition

tempDocument.Content.Find.Replacement.ClearFormatting();

tempDocument.Content.Find.Wrap=Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue;

tempDocument.Content.Find.Execute(

refstrFindPosition,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refforward,

refmissingValue,

refmissingValue,

refstrReplacePosition,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue);

//Replacessalary

tempDocument.Content.Find.Replacement.ClearFormatting();

tempDocument.Content.Find.Wrap=Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue;

tempDocument.Content.Find.Execute(

refstrFindSalary,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refforward,

refmissingValue,

refmissingValue,

refstrReplaceSalary,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue,

refmissingValue);

//Savesandclosesthedocument

tempDocument.Save();

tempDocument.Close(refmissingValue,refmissingValue,refmissingValue);

}

}

}

}如果是webapplication,可能會(huì)出現(xiàn)訪問(wèn)不允許(accessdenied)的問(wèn)題,需要對(duì)iis和web.config進(jìn)行配置。在IIS里選擇工程對(duì)應(yīng)的虛擬目錄,右鍵選擇屬性,在DIRECTORYSECURITY下選擇EDIT,反選anonymousaccess選上Bacisauthentication(我們公司所有的認(rèn)證都是給予LDAP)的;并且在web.config文件中添加<identityimpersonate="true"/>。C#操作WORD的大部分常用方法的使用publicpartialclassThisDocument

{

privateOffice.CommandBarPopupMenuBarItem;

//ArbitraryTagvaluefornewmenuitem.

privateconststringMENU_TAG="DEMO_CODE";

#regionManipulateMenubar

privatevoidInitMenuBarItems()

{

//set{upCommandBars

Office.CommandBarMainMenuBar;

try

{

MainMenuBar=ThisApplication.CommandBars["MenuBar"];

//Attempttofindtheexistingmenubaritem.

this.MenuBarItem=(Office.CommandBarPopup)MainMenuBar.FindControl(Office.MsoControlType.msoControlPopup,missing,MENU_TAG,missing,missing);

if(this.MenuBarItem==null)

{

this.MenuBarItem=(Office.CommandBarPopup)MainMenuBar.Controls.Add(Office.MsoControlType.msoControlPopup,missing,missing,missing,missing);

this.MenuBarItem.Caption="演示(&D)";

this.MenuBarItem.Visible=true;

this.MenuBarItem.Tag=MENU_TAG;

//Addallthesubmenuitems.

//HookUpMenuItem("重置文檔內(nèi)容","ResetDemoText");

//HookUpMenuItem("新建窗口并平鋪","CreateNewWindowAndTile",true);

//HookUpMenuItem("設(shè)置程序標(biāo)題","SetApplicationCaption");

//HookUpMenuItem("切換狀態(tài)欄顯示","ToggleStatusBar");

//HookUpMenuItem("顯示C盤的所有DOC文件","ListAllDocFilesOnC");

//HookUpMenuItem("更改用戶名","ChangeUserName");

//HookUpMenuItem("拼寫檢查","SpellCheckString");

//HookUpMenuItem("顯示“關(guān)于”對(duì)話框","DisplayHelpAbout");

//HookUpMenuItem("移動(dòng)并調(diào)整窗口","MoveAndResizeWindow");

//HookUpMenuItem("啟動(dòng)郵件向?qū)?,"LaunchFaxWizard");

//HookUpMenuItem("顯示“新建”對(duì)話框","DisplayFileNewDialog");

//HookUpMenuItem("顯示“用戶”信息對(duì)話框","DisplayUserInfoDialog");

//HookUpMenuItem("保存“用戶”信息對(duì)話框的更改","DisplayExecuteDialog");

//HookUpMenuItem("隱藏“頁(yè)面設(shè)置”對(duì)話框","HiddenPageSetupDialog");

//HookUpMenuItem("保存所有未保存的文檔","SaveUnsavedDocuments");

//HookUpMenuItem("顯示所選內(nèi)容的類型","ShowSelectionType");

//HookUpMenuItem("在插入點(diǎn)插入文本","InsertTextAtSelection");

//HookUpMenuItem("選擇句子","SelectSentence");

//HookUpMenuItem("格式化區(qū)域并取消","FormatRangeAndUndo");

//HookUpMenuItem("操作區(qū)域中的文本","ManipulateRangeText");

//HookUpMenuItem("創(chuàng)建書簽","CreateBookmarks");

//HookUpMenuItem("顯示所有書簽","ListBookmarks");

//HookUpMenuItem("顯示書簽文本","BookmarkText");

//HookUpMenuItem("在所選內(nèi)容中查找","FindInSelection");

//HookUpMenuItem("在區(qū)域中查找","FindInRange");

//HookUpMenuItem("循環(huán)查找并格式化","FindInLoopAndFormat");

//HookUpMenuItem("替換","SearchAndReplace");

//HookUpMenuItem("替換并恢復(fù)","ReplaceAndRestoreSelection");

//HookUpMenuItem("切換“預(yù)覽”對(duì)話框","TogglePrintPreview");

//HookUpMenuItem("打印文檔","PrintOutDoc");

//HookUpMenuItem("新建表格","CreateTable");

//HookUpMenuItem("添加表格行、列","AddRowAndCol");

//HookUpMenuItem("更新書簽文字","BookmarkText");

//HookUpMenuItem("檢查CAPSLOCK狀態(tài)","CapsLockOn");

//HookUpMenuItem("更改應(yīng)用程序可視","ChangeApplicationVisible");

//HookUpMenuItem("更改用戶姓名","ChangeUserName");

//HookUpMenuItem("關(guān)閉所有文檔","CloseAllDocuments");

//HookUpMenuItem("關(guān)閉所有文檔并保存","CloseAndSave");

//HookUpMenuItem("關(guān)閉單個(gè)文檔并保存","CloseSingleDocumentAndSave");

//HookUpMenuItem("關(guān)閉單個(gè)文檔不保存","CloseSingleDocumentWithoutSave");

//HookUpMenuItem("關(guān)閉并不保存","CloseWithoutSave");

//HookUpMenuItem("折疊區(qū)域","CollapseRange");

//HookUpMenuItem("計(jì)算區(qū)域字符數(shù)","CountRangeCharacters");

//HookUpMenuItem("創(chuàng)建書簽","CreateBookmarks");

//HookUpMenuItem("新建文檔","CreateNewDocument");

//HookUpMenuItem("新建窗口并平鋪","CreateNewWindowAndTile");

//HookUpMenuItem("新建表格","CreateTable");

//HookUpMenuItem("新建表格完整版","CreateTableFull");

HookUpMenuItem("AddRowAndCol","AddRowAndCol");

HookUpMenuItem("BookmarkText","BookmarkText");

HookUpMenuItem("CapsLockOn","CapsLockOn");

HookUpMenuItem("ChangeApplicationVisible","ChangeApplicationVisible");

HookUpMenuItem("ChangeUserName","ChangeUserName");

HookUpMenuItem("CloseAllDocuments","CloseAllDocuments");

HookUpMenuItem("CloseAllDocumentsAndSave","CloseAllDocumentsAndSave");

HookUpMenuItem("CloseSingleDocumentAndSave","CloseSingleDocumentAndSave");

HookUpMenuItem("CloseSingleDocumentWithoutSave","CloseSingleDocumentWithoutSave");

HookUpMenuItem("CloseAllDocumentsWithoutSave","CloseAllDocumentsWithoutSave");

HookUpMenuItem("CollapseRange","CollapseRange");

HookUpMenuItem("CountRangeCharacters","CountRangeCharacters");

HookUpMenuItem("CreateBookmarks","CreateBookmarks");

HookUpMenuItem("CreateNewDocument","CreateNewDocument");

HookUpMenuItem("CreateNewWindowAndTile","CreateNewWindowAndTile");

HookUpMenuItem("CreateTable","CreateTable");

HookUpMenuItem("CreateTableFull","CreateTableFull");

HookUpMenuItem("CriteriaSpecify","CriteriaSpecify");

HookUpMenuItem("DisplayAlerts","DisplayAlerts");

HookUpMenuItem("DisplayApplicationPath","DisplayApplicationPath");

HookUpMenuItem("DisplayExecuteDialog","DisplayExecuteDialog");

HookUpMenuItem("DisplayFileNewDialog","DisplayFileNewDialog");

HookUpMenuItem("DisplayHelpAbout","DisplayHelpAbout");

HookUpMenuItem("DisplaySpellCheckDialog","DisplaySpellCheckDialog");

HookUpMenuItem("DisplayUserInfoDialog","DisplayUserInfoDialog");

HookUpMenuItem("DistrubeColumns","DistrubeColumns");

HookUpMenuItem("FindInLoopAndFormat","FindInLoopAndFormat");

HookUpMenuItem("FindInRange","FindInRange");

HookUpMenuItem("FindInSelection","FindInSelection");

HookUpMenuItem("FinishInitialization","FinishInitialization");

HookUpMenuItem("FormatRangeAndUndo","FormatRangeAndUndo");

HookUpMenuItem("HiddenPageSetupDialog","HiddenPageSetupDialog");

HookUpMenuItem("Initialize","Initialize");

HookUpMenuItem("InitializeDataBindings","InitializeDataBindings");

HookUpMenuItem("InsertBeforeAfterBookmark","InsertBeforeAfterBookmark");

HookUpMenuItem("InsertText","InsertText");

HookUpMenuItem("InsertTextAtSelection","InsertTextAtSelection");

HookUpMenuItem("LaunchFaxWizard","LaunchFaxWizard");

HookUpMenuItem("ListAllDocFilesOnC","ListAllDocFilesOnC");

HookUpMenuItem("ListBookmarks","ListBookmarks");

HookUpMenuItem("ManipulateCell","ManipulateCell");

HookUpMenuItem("ManipulateRangeText","ManipulateRangeText");

HookUpMenuItem("ManipulateTable","ManipulateTable");

HookUpMenuItem("MoveMethod","MoveMethod");

HookUpMenuItem("MoveAndResizeWindow","MoveAndResizeWindow");

HookUpMenuItem("MoveDownMethod","MoveDownMethod");

HookUpMenuItem("MoveStart","MoveStart");

HookUpMenuItem("MoveUpMethod","MoveUpMethod");

HookUpMenuItem("OnShutdown","OnShutdown");

HookUpMenuItem("OpenDocument","OpenDocument");

HookUpMenuItem("PrintOutDoc","PrintOutDoc");

HookUpMenuItem("PrintOutDocument","PrintOutDocument");

HookUpMenuItem("PrintPreviewDocument","PrintPreviewDocument");

HookUpMenuItem("QuitAutoSave","QuitAutoSave");

HookUpMenuItem("QuitPromptToSave","QuitPromptToSave");

HookUpMenuItem("QuitWithoutSave","QuitWithoutSave");

HookUpMenuItem("ReplaceAndRestoreSelection","ReplaceAndRestoreSelection");

HookUpMenuItem("ReplaceBookmarkText","ReplaceBookmarkText");

HookUpMenuItem("ReplaceText","ReplaceText");

HookUpMenuItem("ResetDemoText","ResetDemoText");

HookUpMenuItem("RetrieveStartEnd","RetrieveStartEnd");

HookUpMenuItem("SaveAllDocuments","SaveAllDocuments");

HookUpMenuItem("SaveAsDocument","SaveAsDocument");

HookUpMenuItem("SaveDocumentWithoutPrompt","SaveDocumentWithoutPrompt");

HookUpMenuItem("SaveSingleDocument","SaveSingleDocument");

HookUpMenuItem("SaveSpecifiedDocument","SaveSpecifiedDocument");

HookUpMenuItem("SaveUnsavedDocuments","SaveUnsavedDocuments");

HookUpMenuItem("SearchAndReplace","SearchAndReplace");

HookUpMenuItem("SelectAllContentAsRange","SelectAllContentAsRange");

HookUpMenuItem("SelectRange","SelectRange");

HookUpMenuItem("SelectSentence","SelectSentence");

HookUpMenuItem("SelectSentenceDirectly","SelectSentenceDirectly");

HookUpMenuItem("SelectWholeRange","SelectWholeRange");

HookUpMenuItem("SendArrowKeyLeft","SendArrowKeyLeft");

HookUpMenuItem("SendArrowKeyRight","SendArrowKeyRight");

HookUpMenuItem("SendHomeKeyBegin","SendHomeKeyBegin");

HookUpMenuItem("SendHomeKeyEnd","SendHomeKeyEnd");

HookUpMenuItem("SetApplicationCaption","SetApplicationCaption");

HookUpMenuItem("SetRange","SetRange");

HookUpMenuItem("SetVariousApplicationOptions","SetVariousApplicationOptions");

HookUpMenuItem("ShowSelectionType","ShowSelectionType");

HookUpMenuItem("SpellCheckString","SpellCheckString");

HookUpMenuItem("SwapParagraph","SwapParagraph");

HookUpMenuItem("TogglePrintPreview","TogglePrintPreview");

HookUpMenuItem("ToggleStatusBar","ToggleStatusBar");

}

}

catch(Exceptionex)

{

MessageBox.Show(ex.Message,

ex.Source,MessageBoxButtons.OK,MessageBoxIcon.Error);

}

}

privatevoidHookUpMenuItem(stringstrCaption,stringstrProcToCall)

{

HookUpMenuItem(strCaption,strProcToCall,false);

}

privatevoidHookUpMenuItem(stringstrCaption,stringstrProcToCall,boolBeginNewGroup)

{

Office.CommandBarButtoncbb=CreateButton(strCaption);

cbb.Tag=strProcToCall;

cbb.BeginGroup=BeginNewGroup;

cbb.Click+=newOf

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論