写入Word的自定义属性(转)
来源:互联网 发布:用ansys有限元软件 编辑:程序博客网 时间:2024/05/23 12:08
- Start Visual Studio .NET.
- On the File menu, click New, and then clickProject. SelectWindows Application from the Visual C# Project types. Form1 is created by default.
- Add a reference to Microsoft Word Object Library. To do this, follow these steps:
- On the Project menu, click Add Reference.
- On the COM tab, locate Microsoft Word Object Library, and then clickSelect.
Note Microsoft Office 2003 includes Primary Interop Assemblies (PIAs). Microsoft Office XP does not include PIAs, but they can be downloaded. For additional information about Office XP PIAs, click the article number below to view the article in the Microsoft Knowledge Base:328912 (http://support.microsoft.com/kb/328912/EN-US/ )INFO: Microsoft Office XP PIAs Are Available for Download - Click OK in the Add References dialog box to accept your selections. If you are prompted to generate wrappers for the libraries that you selected, clickYes.
- On the View menu, select Toolbox to display the Toolbox, and then add a button to Form1.
- Double-click Button1. The code window for the form appears.
- In the code window, replace the following codewith:
private void button1_Click(object sender, System.EventArgs e){}
private void button1_Click(object sender, System.EventArgs e){ Word.Application oWord; Word._Document oDoc; object oMissing = Missing.Value; object oDocBuiltInProps; object oDocCustomProps; //Create an instance of Microsoft Word and make it visible. oWord = new Word.Application(); oWord.Visible = true; //Create a new Document and get the BuiltInDocumentProperties collection. oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing); oDocBuiltInProps = oDoc.BuiltInDocumentProperties; Type typeDocBuiltInProps = oDocBuiltInProps.GetType(); //Get the Author property and display it. string strIndex = "Author"; string strValue; object oDocAuthorProp = typeDocBuiltInProps.InvokeMember("Item", BindingFlags.Default | BindingFlags.GetProperty, null,oDocBuiltInProps, new object[] {strIndex} ); Type typeDocAuthorProp = oDocAuthorProp.GetType(); strValue = typeDocAuthorProp.InvokeMember("Value", BindingFlags.Default | BindingFlags.GetProperty, null,oDocAuthorProp, new object[] {} ).ToString(); MessageBox.Show( "The Author is: " + strValue,"Author" ); //Set the Subject property. strIndex = "Subject"; strValue = "The Subject"; typeDocAuthorProp.InvokeMember("Item", BindingFlags.Default | BindingFlags.SetProperty, null,oDocBuiltInProps, new object[] {strIndex,strValue} ); //Add a property/value pair to the CustomDocumentProperties collection. oDocCustomProps = oDoc.CustomDocumentProperties; Type typeDocCustomProps = oDocCustomProps.GetType(); strIndex = "Knowledge Base Article"; strValue = "Q303296"; object[] oArgs = {strIndex,false, MsoDocProperties.msoPropertyTypeString, strValue}; typeDocCustomProps.InvokeMember("Add",BindingFlags.Default | BindingFlags.InvokeMethod, null, oDocCustomProps, oArgs ); MessageBox.Show("Select \"Properties\" from the File menu " + "to view the changes.\nSelect the Summary tab to view " + "the Subject property and the Custom tab to view the Knowledge" + "Base Article property.", "Check File Properties", MessageBoxButtons.OK,MessageBoxIcon.Information);}
- Scroll to the top of the code window, and then add the following lines to the end of the list ofusing directives:
using Microsoft.Office.Core;using Word = Microsoft.Office.Interop.Word;using System.Reflection;
- Press F5 to run the application.
- 写入Word的自定义属性(转)
- C# 操作 Word 修改word的高级属性中的自定义属性
- C# 操作 Word 修改word的高级属性中的自定义属性
- word的读取与写入
- 写入word
- 自定义view的自定义属性
- 自定义控件的自定义属性
- 自定义控件的自定义属性
- C# 写入Word
- NSUserDefaults写入和读取自定义的对象
- 自定义对象的写入和读出函数
- log4net把自定义的变量写入数据库
- 读取shp属性表导出为excel表格和写入word文档
- 自定义标签的属性
- 自定义javabean的属性
- 自定义UINavigationBar的属性
- 自定义属性加上的
- 自定义属性的使用方法
- 程序性能 CPU cache
- 一段可输入下拉框html代码
- C# 判断文件是否为空
- Activity中启动其他包里的Activity摘要
- Linux忘记密码解决方案 <grub篇>
- 写入Word的自定义属性(转)
- 西蒙iphone-OpenGL ES 教程-01
- Android ListView反复调用getView和getCount
- Spring单例Bean和线程安全
- 吸血鬼教授vs狼人工程师
- atemega8例程:灯闪烁
- Java 多线程的Thread类和Runnable接口
- java 访问数据库
- 初识ubuntu-尝试配置安全可靠的web服务器