object oMissing = System.Reflection.Missing.Value;
object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined book *///Start Word and create a new document.
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
oWord.Visible = true;
object oTemplate = "d:\\f\\word\\MyTemplate.dot";
oDoc = oWord.Documents.Add(ref oTemplate, ref oMissing,
ref oMissing, ref oMissing);object oMissing = System.Reflection.Missing.Value;
object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined book *///Start Word and create a new document.
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
oWord.Visible = true;
object oTemplate = "d:\\f\\word\\MyTemplate.dot";
oDoc = oWord.Documents.Add(ref oTemplate, ref oMissing,
ref oMissing, ref oMissing);
object oBookMark = "MyBook";
Word.Table oTable;
Word.Range wrdRng = oDoc.Books.Item(ref MyBook).Range;//(错误在这句)
object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined book *///Start Word and create a new document.
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
oWord.Visible = true;
object oTemplate = "d:\\f\\word\\MyTemplate.dot";
oDoc = oWord.Documents.Add(ref oTemplate, ref oMissing,
ref oMissing, ref oMissing);object oMissing = System.Reflection.Missing.Value;
object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined book *///Start Word and create a new document.
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
oWord.Visible = true;
object oTemplate = "d:\\f\\word\\MyTemplate.dot";
oDoc = oWord.Documents.Add(ref oTemplate, ref oMissing,
ref oMissing, ref oMissing);
object oBookMark = "MyBook";
Word.Table oTable;
Word.Range wrdRng = oDoc.Books.Item(ref MyBook).Range;//(错误在这句)
ref MyBook--MyBook你没有定义啊!
单独编译slope为windows应用程序运行是没有问题的。只是编译为DLL,然后被work项目引用就出现问题了。
{
oDoc = oWord.Documents.Add(ref oTemplate, ref oMissing,
ref oMissing, ref oMissing);
}
else
{
MessageBox.Show("Null");
}
{
oDoc = oWord.Documents.Add(ref oTemplate, ref oMissing,
ref oMissing, ref oMissing);
}
else
{
MessageBox.Show("Null");
}
应该是oDoc.Books.Item(ref MyBook)为null,在slope编译的windows应用程序,执行那段没有问题。把他编译为dll被work引用的时候,slope作为work窗体的一个子窗体,这种情况下就不行了。
调用slope.dll的代码是:Assembly asm = Assembly.LoadFile(System.Windows.Forms.Application.StartupPath+"\\slope.dll");
Type formType = asm.GetType("slope.Form1");
Form[] charr = this.MdiChildren;
Form frm = OpenForm(formType);Form OpenForm(Type formType)
{
Form frm = formType.InvokeMember(null,
BindingFlags.DeclaredOnly
| BindingFlags.Public
| BindingFlags.NonPublic
| BindingFlags.Instance
| BindingFlags.CreateInstance,
null, null, null) as Form;
frm.MdiParent = this;
frm.Show();
return frm;
}
是这句的路径不对。