资源简介

http://blog.csdn.net/zengweiqiang/article/details/6872259 根据这篇博客做出来的可运行程序和源码。 用vs2010写的

资源截图

代码片段和文件信息

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 = Microsoft.Office.Interop.Word;
using System.IO;
using System.Diagnostics;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private static Word._Document wDoc = null;
        private static Word._Application wApp = null;
        string[] sReplace;

        private void button1_Click(object sender EventArgs e)
        {
            Word.Application thisApplication = new Word.ApplicationClass();
            wApp = thisApplication;
            string tmpDocFile = Directory.GetCurrentDirectory() + @“\template.doc“;
            object templatefile = tmpDocFile;
            object missing =System.Reflection.Missing.Value  ;
            //object missing = Type.Missing;
            wDoc = wApp.Documents.Add(ref templatefile ref missing  ref missing ref missing);
            wDoc.Activate();

            //object replaceAll = Word.WdReplace.wdReplaceAll;
            for (int i = 0; i             {
                object replaceAll = Word.WdReplace.wdReplaceOne;
                wApp.Selection.Find.ClearFormatting();
                wApp.Selection.Find.Text = “***“;
                wApp.Selection.Find.Format = true;
                wApp.Selection.Find.MatchByte = true;
                wApp.Selection.Find.Wrap = Word.WdFindWrap.wdFindAsk;
                wApp.Selection.Find.Replacement.ClearFormatting();
                wApp.Selection.Find.Replacement.Text = sReplace[i];
                wApp.Selection.Find.Execute(ref missing ref missing ref missing ref missing ref missing
                                            ref missing ref missing ref missing ref missing ref missing
                                            ref replaceAll ref missing ref missing ref missing ref missing);
                
            }
            object background = false;
            object filename = Directory.GetCurrentDirectory() + @“\t.doc“;
            wDoc.SaveAs2(ref filename ref missing    ref missing ref missing ref missing ref missing ref missing ref
                         missing ref missing ref missing ref missing ref missing ref missing ref missing ref missing ref missing);
            
            wDoc.PrintOut(ref background ref missing ref missing ref missing ref missing ref missing ref missing ref
                          missing ref missing ref missing ref missing ref missing ref missing ref missing ref missing ref missing ref missing
                          ref missing);

            object saveOPtion = Word.WdSaveOptions.wdSaveChanges;
            wDoc.Close(ref saveOPtionref missingref missing );
            s

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2014-03-19 17:00  WindowsFormsApplication1\
     目录           0  2014-03-19 15:50  WindowsFormsApplication1\WindowsFormsApplication1\
     文件        2106  2014-03-19 18:46  WindowsFormsApplication1\WindowsFormsApplication1\Form1.Designer.cs
     文件        3848  2014-03-19 18:47  WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs
     文件        5817  2014-03-19 18:46  WindowsFormsApplication1\WindowsFormsApplication1\Form1.resx
     文件        2048  2014-03-19 14:33  WindowsFormsApplication1\WindowsFormsApplication1\Form2.Designer.cs
     文件        3189  2014-03-19 14:33  WindowsFormsApplication1\WindowsFormsApplication1\Form2.cs
     文件        5817  2014-03-19 14:33  WindowsFormsApplication1\WindowsFormsApplication1\Form2.resx
     文件         505  2014-03-19 15:40  WindowsFormsApplication1\WindowsFormsApplication1\Program.cs
     目录           0  2014-03-18 17:13  WindowsFormsApplication1\WindowsFormsApplication1\Properties\
     文件        1398  2014-03-18 17:13  WindowsFormsApplication1\WindowsFormsApplication1\Properties\AssemblyInfo.cs
     文件        2900  2014-03-18 17:13  WindowsFormsApplication1\WindowsFormsApplication1\Properties\Resources.Designer.cs
     文件        5612  2014-03-18 17:13  WindowsFormsApplication1\WindowsFormsApplication1\Properties\Resources.resx
     文件        1111  2014-03-18 17:13  WindowsFormsApplication1\WindowsFormsApplication1\Properties\Settings.Designer.cs
     文件         249  2014-03-18 17:13  WindowsFormsApplication1\WindowsFormsApplication1\Properties\Settings.settings
     文件        4999  2014-03-19 17:24  WindowsFormsApplication1\WindowsFormsApplication1\WindowsFormsApplication1.csproj
     目录           0  2014-03-19 18:48  WindowsFormsApplication1\WindowsFormsApplication1\bin\
     目录           0  2014-03-19 16:55  WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\
     文件       11776  2014-03-19 16:42  WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe
     文件       28160  2014-03-19 16:42  WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.pdb
     目录           0  2014-03-18 17:13  WindowsFormsApplication1\WindowsFormsApplication1\obj\
     目录           0  2014-03-18 17:13  WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\
     目录           0  2014-03-19 18:48  WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\
     文件         789  2014-03-18 17:13  WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        6575  2014-03-19 18:48  WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     目录           0  2014-03-19 18:49  WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\TempPE\
     文件         180  2014-03-19 18:46  WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.Form1.resources
     文件         180  2014-03-19 17:29  WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.Form2.resources
     文件         180  2014-03-19 17:29  WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.Properties.Resources.resources
     文件        1848  2014-03-19 17:19  WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.csproj.FileListAbsolute.txt
     文件        1091  2014-03-19 18:46  WindowsFormsApplication1\WindowsFormsApplication1\obj\x86\Debug\WindowsFormsApplication1.csproj.GenerateResource.Cache
............此处省略7个文件信息

评论

共有 条评论