c#替换word里的词和向word里表格添加数据
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Office.Interop.Word;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
String fileName = "20150907";
String sourceFileName = @"C:\Users\逍遥\Desktop\SuccessReport\Template\old.doc";
String destFileName = @"C:\Users\逍遥\Desktop\SuccessReport\New\" + fileName + ".doc";
if (System.IO.File.Exists(destFileName))
{
System.IO.File.Delete(destFileName);
}
System.IO.File.Copy(sourceFileName, destFileName);
Microsoft.Office.Interop.Word.Application app = new Application(destFileName);
Microsoft.Office.Interop.Word.Document doc = new Document();
doc = app.Documents.Open(destFileName);
String content = doc.Paragraphs[1].Range.Text.Trim();
Console.WriteLine(content);
doc.Paragraphs[1].Range.Text.Replace("关键词1", "哈哈");
doc.Save();
doc.Close();
app.Quit();
}
}
}
我写的没有实现这个功能
还要实现填写word里的表格