c#替换word里的词和向word里表格添加数据

asdfghjkl0128 2015-09-11 07:24:15
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里的表格
...全文
176 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
asdfghjkl0128 2015-09-11
  • 打赏
  • 举报
回复
向word里的表格填数据写完了,但是向word里填词,也就是替换word里的词的功能没有完成 向word里的表格填数据的代码: Microsoft.Office.Interop.Word.Table table = doc.Tables[1]; String value = table.Cell(1, 1).Range.Text; table.Cell(4, 4).Range.Text = "呵呵"; Console.WriteLine(value);

111,125

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧