C#读取Word并在指定位置插入文本
2021-04-22 08:26
标签:miss oid key using pac off class 分享 type C#读取Word并在指定位置插入文本 标签:miss oid key using pac off class 分享 type 原文地址:http://www.cnblogs.com/xinyibufang/p/8022374.htmlusing System;
using System.IO;
using System.Reflection;
using MWord = Microsoft.Office.Interop.Word;
namespace ConsoleApp3
{
class Program
{
static void Main(string[] args)
{
MWord.Application app = new Microsoft.Office.Interop.Word.Application();
MWord.Document doc = null;
object unknow = Type.Missing;
app.Visible = true;
string str = @"F:\2.doc";
object file = str;
doc = app.Documents.Open(ref file,
ref unknow, ref unknow, ref unknow, ref unknow,
ref unknow, ref unknow, ref unknow, ref unknow,
ref unknow, ref unknow, ref unknow, ref unknow,
ref unknow, ref unknow, ref unknow);
//循环输出所有内容
for (int i = 1; i )
{
string temp = doc.Paragraphs[i].Range.Text.Trim();
Console.WriteLine(temp);
}
object bk = "电话"; //word书签
if (doc.Bookmarks.Exists("电话"))
{
doc.Bookmarks.get_Item(bk).Range.Text = "insert text"; // 插入文本
}
Console.ReadKey();
}
}
}
文章标题:C#读取Word并在指定位置插入文本
文章链接:http://soscw.com/index.php/essay/77987.html