读书人

VC.net打开dot文件有有关问题C#代码

发布时间: 2012-01-01 23:10:55 作者: rapoo

VC.net打开dot文件有问题,C#代码正常,烦死了
想打开一个dot文件,输入文字,C#代码正常,VC.net异常,困扰几天了,烦呀...
//--------------------------------------------C#
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.ApplicationClass ();

object oMissing = System.Reflection.Missing.Value;
object Nothing = System.Reflection.Missing.Value;
object otemp ="e:\\hmh.dot"
oWord.Visible = false ;
oDoc = oWord.Documents.Add(ref otemp, ref oMissing,ref oMissing, ref oMissing);

object x = "name";
Word.Bookmark bm = oDoc.Bookmarks.Item(ref x);
bm.Range.Text = "Test_Name";//--正常,有Text属性!!!

object fn = "e:\\a1.doc";

oDoc.SaveAs(ref fn, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
oWord.Documents.Close(ref Nothing, ref Nothing, ref Nothing);
oWord.Quit(ref Nothing, ref Nothing, ref Nothing);


//--------------------------------------------VC
Word:: _Application^ oWord;
Word::_Document^ oDoc;
oWord = gcnew Word::ApplicationClass ();

Object^ oMissing = System::Reflection::Missing::Value;
Object^ Nothing = System::Reflection::Missing::Value;
Object^ otemp ="e:\\hmh.dot" ;//GetDirectoryFromFile(System::Windows::Forms::Application::ExecutablePath)+@"Customers::dot";

oWord->Visible = true ;
oDoc = oWord->Documents->Add( otemp, oMissing, oMissing, oMissing);
System::Object^ x = "name";
Word::Bookmark^ bm = oDoc->Bookmarks->Item(x) ;
bm->Range->Text ----->没有Text属性???
我仔细比较了引用的Dll“Interop.Word.dll”,是一样的版本,这是为何???
恳求高手指点...

[解决办法]
try

bm->Range->SetText
[解决办法]

bm->Range.Text

读书人网 >VC

热点推荐