In general, I make a report with the replacement of certain words with specific meanings ... It is necessary that the changes in the file remain ... But for some reason, the limited functionality mode works for me ... In what methods, in what parameters is this put? Work in .doc and .docx formats

 private void button4_Click(object sender, EventArgs e) { //Создаём новый Word.Application Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application(); //Загружаем документ Microsoft.Office.Interop.Word.Document doc = null; object fileName = "E:\\R.doc"; object falseValue = false; object trueValue = true; object missing = Type.Missing; doc = app.Documents.Open(ref fileName, ref missing, ref trueValue, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); //Теперь у нас есть документ который мы будем менять. //Очищаем параметры поиска app.Selection.Find.ClearFormatting(); app.Selection.Find.Replacement.ClearFormatting(); //Задаём параметры замены и выполняем замену варианта применеия. object findText = "<VARIANT>"; object replaceWith = "на что меняем"; object replace = 2; app.Selection.Find.Execute(ref findText, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref replaceWith, ref replace, ref missing, ref missing, ref missing, ref missing); app.Visible = true; app.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone; doc.Saved = true; //doc.Close(Microsoft.Office.Interop.Word.WdSaveOptions.wdSaveChanges); //app.Quit(false); } 
  • one
    Can i ask you? And why are you writing such a coaster with a bunch of ref ? After all, to open for example, you can simply use app.Documents.Open("Путь"); this is hundreds of times more beautiful and more comfortable! - EvgeniyZ
  • The thing is, I’m only getting it right with C # at all - Bumable
  • I will now know - Bumable

1 answer 1

RTF files always open in reduced functionality mode.

Use native .doc or .docx formats depending on the version.

  • Well ... Then a similar question with the formats .doc and .docx .... I have the same problem with them .... To be more precise, I started with them .. - Bumable