C#操作Word文档(Office 2007)

首先引入类库,Microsoft.Office.Interop.Word,然后进行编程。代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Office.Interop.Word; 数据挖掘交友

namespace WordTest
{
    public partial class Form1 : Form
    {
        object strFileName;
        Object Nothing;
        Microsoft.Office.Interop.Word.Application myWordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
        Document myWordDoc;
        string strContent = "";

        public Form1()
        {
            InitializeComponent();
        }

数据挖掘交友

        private void button1_Click(object sender, EventArgs e)
        {
            createWord();      
            //openWord();
        }

数据挖掘实验室

        private void createWord()
        {
            strFileName = System.Windows.Forms.Application.StartupPath + "test.doc";
            if (System.IO.File.Exists((string)strFileName))
                System.IO.File.Delete((string)strFileName);
            Object Nothing = System.Reflection.Missing.Value;
            myWordDoc = myWordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing); 数据挖掘研究院

            #region 将数据库中读取得数据写入到word文件中

            strContent = "你好 ";
            myWordDoc.Paragraphs.Last.Range.Text = strContent; 数据挖掘实验室

            strContent = "这是测试程序";
            myWordDoc.Paragraphs.Last.Range.Text = strContent;

数据挖掘研究院


            #endregion 数据挖掘实验室

            //将WordDoc文档对象的内容保存为DOC文档
            myWordDoc.SaveAs(ref strFileName, 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);
            //关闭WordDoc文档对象
            myWordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
            //关闭WordApp组件对象
            myWordApp.Quit(ref Nothing, ref Nothing, ref Nothing);

数据挖掘工具

            this.richTextBox1.Text = strFileName + " " + "创建成功"; 数据挖掘交友

        }
        private void openWord()
        {
            fontDialog1.ShowDialog();
            System.Drawing.Font font = fontDialog1.Font;
            object filepath = "D:\asp.docx";
            object oMissing = System.Reflection.Missing.Value;
            myWordDoc = myWordApp.Documents.Open(ref filepath, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); 数据挖掘论坛
            myWordDoc.Content.Font.Size = font.Size;
            myWordDoc.Content.Font.Name = font.Name;
            myWordDoc.Save();
            richTextBox1.Text = myWordDoc.Content.Text;
           
           
            myWordDoc.Close(ref oMissing, ref oMissing, ref oMissing);
            myWordApp.Quit(ref oMissing, ref oMissing, ref oMissing);
        }

} 数据挖掘论坛

http://www.cnblogs.com/wrtandy/archive/2006/12/13/andy.html

[数据挖掘专家] [数据挖掘研究院] [数据挖掘论坛] [数据挖掘实验室]
上一篇:用C#动态创建Access数据库
下一篇:c语言精华
最新评论共有 0 位网友发表了评论 , 查看所有评论
发表评论( 不能超过250字,需审核,请自觉遵守互联网相关政策法规。 )
匿名?
数据挖掘网站导航 数据挖掘论坛导航
  • 数据挖掘工具
  • 数据挖掘论坛
  • DataCruncher - Cognos
  • MineSet - MathSoft
  • Intelligent Miner - GainSmarts
  • Sqlserver - SAS - Clementine
  • CART - Weka - WizSoft
  • NeuroShell - ModelQuest
  • data mining tools - Darwin
  • 数据挖掘交友
  • 数据挖掘博客
  • 数据挖掘工具
  • 数据挖掘资源
  • 数据挖掘技术算法
  • 数据挖掘相关期刊、会议
  • 研究院联盟合作专区
  • 数据挖掘基础与相关技术
  • 数据挖掘厂商与就业
  • 数据挖掘研究者乐园
  • 知名厂商数据挖掘工具资料
  • 国内数据挖掘实验室
  • Foreign Data Mining Lab
  • 热点关注
  • 挑战C#学习的最快速度
  • C#模仿QQ截图功能
  • C# 关于开机自动运行程序方式之一
  • 第一章 C#简介
  • 利用C#实现分布式数据库查询
  • Visual Studio 2005 Hands-On Tutorial - P
  • C#入门代码
  • .NET架构与模式探索
  • 用C#代码编写的SN快速输入工具
  • C# 关于开机自动运行程序方式之一
  • 论坛最新话题
  • Foundations of Statistical Natural Langu
  • Game Theory meet Data Mining: A Recent P
  • System Building: How does it help or hin
  • 数据挖掘与Clementine培训
  • 新手报到
  • 求 SASEM 客户流失预测分析
  • 数据挖掘工程师/搜索研究院—北京——无线
  • 数据挖掘入门介绍(如何着手数据挖掘)
  • Information Overload Survey Results
  • The INEX 2005 Workshop on Element Retrie
  • 相关资讯
  • 彻底剖析C# 2.0泛型类的创建和使用
  • 对C# 2.0中匿名方法的怀疑分析
  • EasySP管理解决方案基于Microsoft .NET架构
  • .NET架构与模式探索
  • .NET架构的核心开发技术
  • 用C#代码编写的SN快速输入工具
  • C#链接数据库技巧
  • C#设计模式编程之抽象工厂模式新解
  • 第一章 C#简介
  • 第七章 异常处理
  • 数据挖掘实验室资料
  • 数据挖掘博客地址
  • 数据挖掘实验室网站地址
  • Prepare for Medicare audits by using dat
  • 注册成为SAS用户与爱好者俱乐部会员
  • 水南梅
  • 明日烟
  • 新人报道
  • 下载
  • 厦门服务器托管,450元/月—0592-5177319 高
  • 买空间送域名--0592-5177319 高静