المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Word Interop: Unable to save text in a document



C# Programming
11-17-2009, 01:30 PM
Hi

Got stuck here. Word document gets saved in the correct directory with the correct name but the typed text doesn't persist. Please help. (*I have tested that the text is actually typed in the active document).

private void SaveDoc()
{
Word.Application wdApp;
Word.Document wdDoc;
wdApp = new Word.Application();
wdDoc = wdApp.Documents.Add(ref missing, ref missing, ref missing, ref missing);

//type some text
wdApp.Selection.TypeText("Some Heading"));

//set rtf doc paragraph 1 style to normal
object wdParaStyleName = "Heading 1"
wdDoc.Paragraphs[1].set_Style(ref wdParaStyleName);

//save rtf doc
wdApp.ChangeFileOpenDirectory("C:\\test\\");
object wdFileName = "TestDoc.rtf"
object saveFmt = Word.WdSaveFormat.wdFormatRTF;
wdApp.ActiveDocument.SaveAs(ref wdFileName, ref saveFmt, ref falseO, ref missing, ref falseO, ref missing, ref trueO, ref falseO, ref falseO, ref trueO, ref falseO, ref missing, ref falseO, ref falseO, ref missing, ref falseO);

//Quit Word
object saveChanges = Word.WdSaveOptions.wdDoNotSaveChanges;
wdApp.Quit(ref saveChanges, ref missing, ref missing);
}

Using doc.save() prompts the save dialog which defeats the purpose of automation.

Thanks
GJ