1、将文档另存为及替换操作
1、另存为
【提示】:在“C#读写Word文件(一)”【方式二】打开word文档的基础上进行操作
MSWord.Paragraph para = doc.Content.Paragraphs.Add(ref Nothing);
para.Range.Paste();
para.Range.InsertParagraphBefore();//添加一次回车
object newName = Directory.GetCurrentDirectory()+@"\新建文档.doc";
doc.SaveAs(ref newName, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);//另存为
2、查找替换操作
【例一】按照内容查找以及替换
string strDir = Directory.GetCurrentDirectory();
string docName = strDir + @"\test.doc";
object Nothing = System.Reflection.Missing.Value; //一个编程时需要经常使用的一个参数
MSWord.ApplicationClass wordapp = null; //这是MSWord程序,在这个程序下,可以同时打开多个文档
MSWord.Document doc = null; //需要打开的MSWord文档
object docObject = docName; //由于COM操作中,都是使用的 object ,所以,需要做一些转变
if (!File.Exists(docName))
{
File.Create(docName);
}
wordapp = new MSWord.ApplicationClass();
wordapp.Visible = true; //所打开的MSWord程序,是否是可见的
Object isVisible = true;
doc = wordapp.Documents.Open(ref docObject, ref Nothing, ref Nothing,
ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing,
ref Nothing, ref Nothing, ref Nothing, ref isVisible, ref Nothing,
ref Nothing, ref Nothing, ref Nothing);
strin