当前位置: 代码迷 >> VC >> VC.net打开dot文件有有关问题,C#代码正常,烦死了
  详细解决方案

VC.net打开dot文件有有关问题,C#代码正常,烦死了

热度:9632   发布时间:2013-02-25 00:00:00.0
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
  相关解决方案