도움이 나는 마누엘이 언급 한 것처럼 책갈피를 사용하여 할 수있는 방법을 발견 :
string[] readText = File.ReadAllLines(@"p:\CARTAP1.txt");
// declare objects and variables
object fileName = @"P:\PreciboCancelado.doc";
object readOnly = false;
object isVisible = true;
object missing = System.Reflection.Missing.Value;
// create instance of Word
Microsoft.Office.Interop.Word.ApplicationClass oWordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
// Create instance of Word document
Microsoft.Office.Interop.Word.Document oWordDoc = new Document();
// Open word document.
oWordDoc = oWordApp.Documents.Open(ref fileName, ref missing, ref readOnly, ref readOnly,
ref missing, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing);
oWordDoc.Activate();
// Debug to see that I can write to the document.
oWordApp.Selection.TypeText("This is the text that was written from the C# program! ");
oWordApp.Selection.TypeParagraph();
// Example of writing to bookmarks each bookmark will have exists around it to avoid null.
if (oWordDoc.Bookmarks.Exists("Fecha"))
{
// set value for bookmarks
object oBookMark = "Fecha";
oWordDoc.Bookmarks.get_Item(ref oBookMark).Range.Text = readText[2] ;
oBookMark = "Nombre";
oWordDoc.Bookmarks.get_Item(ref oBookMark).Range.Text = readText[3];
}
// Save the document.
oWordApp.Documents.Save(ref missing, ref missing);
// Close the application.
oWordApp.Application.Quit(ref missing, ref missing, ref missing);
[C#을 사용하여 파일에 문자를 삽입하는 방법 (HTTP의
가능한 중복 : // 유래 .com/questions/98484/how-to-a-file-using-c-sharp) – meJustAndrew
구멍 문서를 읽고 다시 쓰면서 새로운 텍스트를 추가해야합니다. 누군가가 이것 [여기] (http://stackoverflow.com/questions/98484/how-to-insert-characters-to-a-file-using-c-sharp)을 물었고 비슷한 대답을 얻었습니다. – meJustAndrew
나는 워드 문서에 익숙하지가 않다.하지만 그것이 나라면 Intellisence 및/또는 [디버거]를 이용할 것이다. (http://www.codeproject.com/Articles/79508/Mastering-Debugging -in-Visual-Studio-A-Beginn)과'Document'에서 발견 된 속성과 메소드를 확인하십시오. 'Document' 객체를 편집하여 저장하고 기존 파일을 덮어 쓸 것입니다. –