C#窗体打开word-替换标签内容
来源:互联网 发布:北方数据 杂志 编辑:程序博客网 时间:2024/05/18 01:23
http://download.csdn.net/detail/small5e4444/3845421
using System;
using System.Collections.Generic;using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Word;//这个在VS2008中没找到引用,是从别的地方找到的dll,我把整个程序传到了资源里
namespace word_1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Word.ApplicationClass WordApp = new Word.ApplicationClass();
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
object fileName = openFileDialog1.FileName;
object readOnly = false;
object isVisible = true;
object missing = System.Reflection.Missing.Value;
WordApp.Visible = true;
Word.Document aDoc = WordApp.Documents.Open(ref fileName, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing);
aDoc.Activate();
WordApp.Selection.TypeText("Copyright C# Corner"); //给文档添加标题
WordApp.Selection.TypeParagraph();
}
}
private void button2_Click(object sender, EventArgs e)
{
Word.ApplicationClass WordApp = new Word.ApplicationClass();
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
count++;
object fileName = openFileDialog1.FileName;
object readOnly = false;
object isVisible = true;
object missing = System.Reflection.Missing.Value;
WordApp.Visible = true;
Word.Document aDoc = WordApp.Documents.Open(ref fileName, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing);
aDoc.Activate();
//WordApp.Selection.TypeText("Copyright C# Corner"); 给文档添加标题
WordApp.Selection.TypeParagraph();
object markName = "A";//书签标记
Bookmark bm = aDoc.Bookmarks.get_Item(ref markName);
bm.Range.Text = "nnnnn";//替换的内容
markName = "B";//书签标记
bm = aDoc.Bookmarks.get_Item(ref markName);
bm.Range.Text = "bbbbb";//替换的内容
}
}
}
}
- C#窗体打开word-替换标签内容
- C#替换Word中的文本内容
- C#实现WORD文档的内容复制和替换
- c#对Aspose.Word替换书签内容的简单封装
- c# 窗体插入WORD
- C#窗体打开EXCEL
- java采用压缩解压缩方式修改word中内容或替换标签
- c# 打开word
- C# 打开word
- C#打开word
- C#打开Word
- C#打开Word
- C#打开Word
- asp 替换指定标签内容
- C#读取Word内容
- C#操作word标签
- 关于C#替换Word文本框中的内容(不使用Bookmark)疑问
- 黄聪:C#实现WORD文档的内容复制和替换
- Web开发人员和设计师必读文章推荐
- Android 通过伪3D变换可以基本实现coverflow的效果
- 博客 UTF-8 测试1
- 九个让人难以置信的HTML5和JavaScript实验
- 下载文件
- C#窗体打开word-替换标签内容
- sysfs目录下的usb设备信息浅析--ft232
- Web开发者必备的20款超赞jQuery插件
- reset的失效问题
- 也谈Linux下使用freetds连接sqlserver数据库
- 今天心情好差
- epoll_create epoll_ctl epoll_wait close epoll和select的简单比较
- Web开发人员常用速查手册
- 资治通鉴,卷八十二,对老庄的批驳,《崇有论》