书签问题-使用C#自动化Microsoft Word [英] Bookmarks problems - automating Microsoft Word with C#
本文介绍了书签问题-使用C#自动化Microsoft Word的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
每行定义的所有代码.
All the code with definitions of each line.
private void button1_Click(object sender, EventArgs e)
{
object oMissing = System.Reflection.Missing.Value;
object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */
//Start Word and create a new document.
Word._Application oWord; //Define
Word._Document oDoc; //Define
oWord = new Word.Application();//start Word
oWord.Visible = true;//show Word
Object oTemplatePath = "C:\\social_assesment_templ.doc";//find the document
oDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing); //load social_assesment_templ.doc into the document
Object oBookMark = "Applicant_name"; //A bookmark in the doc file.
oDoc.Bookmarks.Item(ref oBookMark).Range.Text = "John Doe";//change ''oBookMark''''s text range to "John Doe"
Object fileName = "C:\\TestFile.doc";//Set new file name
oDoc.SaveAs(ref fileName,ref oMissing, ref oMissing,ref oMissing, ref oMissing,ref oMissing, ref oMissing,ref oMissing, ref oMissing,ref oMissing, ref oMissing, ref oMissing,ref oMissing, ref oMissing,ref oMissing, ref oMissing);//save as ''filename''
}
这是我无法弄清的问题所在:
here is the line with problems that I can''t figure out:
oDoc.Bookmarks.Item(ref oBookMark).Range.Text = "John Doe";//change ''oBookMark''''s text range to "John Doe"//The ''Item'' is underlined: ...Word.Bookmarks does not contain a definition of ''Item''. However, I found this on one of microsoft''s sites.
谢谢.
Thank You.
推荐答案
我认为您可能是来自两个站点的混合代码:Word._Document.SaveAs需要16个参数: ^ ](我希望使用的Word.Document.SaveAs也是如此).
返回从中获取代码的站点,并仔细查看-我想您错过了一些东西!如果没有其他内容,如果没有原始站点的参考,我们将无法为您提供真正的帮助!
I think perhaps you have mixed code from two sites: Word._Document.SaveAs takes 16 parameters: MSDN[^] (and so does the Word.Document.SaveAs which is the one I would expect to use).
Go back to the site you got the code from, and look more closely - I think you have missed something! If nothing else, without teh original site for reference, we can''t really help you much!
替换:
oDoc.Bookmarks.Item(ref oBookMark).Range.Text = "John Doe";
与:
with:
oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text = "John Smith";
这篇关于书签问题-使用C#自动化Microsoft Word的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文