|
c#生成world文档 using System;
using System.Reflection;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Type wordType = Type.GetTypeFromProgID("Word.Application");//得到Word的进程ID
Object word = Activator.CreateInstance(wordType);//构建Word实例
wordType.InvokeMember("Visible", BindingFlags.SetProperty, null, word, new Object[] { true });//调用指定成员
Object documents = wordType.InvokeMember("Documents", BindingFlags.GetProperty, null, word, null);
Object document = documents.GetType().InvokeMember("Add", BindingFlags.InvokeMethod, null, documents, null);
}
}
}
|
|