• 大小: 195KB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2021-06-19
  • 语言: C#
  • 标签: word  类库  pixysoft  office  

资源简介

c# 操作word强大类库(牛人版) 一个很好的操作实例!

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Text;
using Word;
using System.Data;
using System.Collections;

namespace Pixysoft.Office
{
    /// 
    /// 支持创建、打开、保存、关闭文档
    /// 支持页面设置
    /// 支持普通文字输入设置
    /// 支持表插入
    /// 支持BookMark
    /// 

    public class WordDocuments
    {
        private bool visible = false;

        private object oEndOfDoc = “\\endofdoc“; /* \endofdoc is a predefined bookmark */
        private object oMissing = System.Reflection.Missing.Value;

        Word._Application oWord;
        Word._Document oDoc;

        Hashtable templTableHash = new Hashtable();

        #region 文件操作
        /// 
        /// 新建一个空文档
        /// 

        public void CreateDocument()
        {
            CloseDocument();
            oWord = new Word.Application();
            oWord.Visible = visible;
            oDoc = oWord.Documents.Add(ref oMissing ref oMissing ref oMissing ref oMissing);
        }
        /// 
        /// Creates the document with template.
        /// 

        public void CreateDocumentWithTemplate(object path)
        {
            CloseDocument();
            oWord = new Word.Application();
            oWord.Visible = visible;
            oDoc = oWord.Documents.Add(ref path ref oMissing ref oMissing ref oMissing);
            templTableHash.Clear();
            int i = 0;
            foreach (Word.Table table in oDoc.Tables)
            {
                templTableHash.Add(i table);
                i++;
            }
        }
        /// 
        /// 打开项目
        /// 

        /// The path.
        public void OpenDocument(object path)
        {
            CloseDocument();
            oWord = new Word.Application();
            oWord.Visible = visible;
            oDoc = oWord.Documents.Open(ref path
            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);
            templTableHash.Clear();
            int i = 0;
            foreach (Word.Table table in oDoc.Tables)
            {
                templTableHash.Add(i table);
                i++;
            }
        }
        /// 
        /// 保存当前项目
        /// 

        public void SaveDocument()
        {
            if (oWord == null)
                throw new Exception(“Create / Open Document first!“);
            if (oDoc == null)
                throw new Exception(“Create / Open Document first!“);
            if (!oDoc.Saved)
                oDoc.Save();
        }
        /// 
        /// 项目另存为
        /// 

        public void SaveAsDocument(object path)
        {
            if (oWord == null)
                thro

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       6144  2007-05-30 22:43  Pixysoft.Office\bin\Debug\Interop.otkloadr.dll

     文件      57344  2007-05-30 22:43  Pixysoft.Office\bin\Debug\Interop.VBIDE.dll

     文件     655360  2007-05-30 22:43  Pixysoft.Office\bin\Debug\Interop.Word.dll

     文件      32768  2007-06-04 11:34  Pixysoft.Office\bin\Debug\Pixysoft.Office.dll

     文件      54784  2007-06-04 11:34  Pixysoft.Office\bin\Debug\Pixysoft.Office.pdb

     目录          0  2007-06-19 00:08  Pixysoft.Office\bin\Debug

     目录          0  2007-06-18 20:39  Pixysoft.Office\bin

     文件       3641  2007-05-30 22:43  Pixysoft.Office\Documents\ClassDiagram.cd

     文件        545  2007-05-30 22:43  Pixysoft.Office\Documents\TestClass.txt

     目录          0  2007-06-18 20:39  Pixysoft.Office\Documents

     文件      32768  2007-06-04 11:34  Pixysoft.Office\obj\Debug\Pixysoft.Office.dll

     文件      54784  2007-06-04 11:34  Pixysoft.Office\obj\Debug\Pixysoft.Office.pdb

     目录          0  2007-06-19 00:08  Pixysoft.Office\obj\Debug\Refactor

     文件       6749  2007-06-04 13:15  Pixysoft.Office\obj\Debug\ResolveAssemblyReference.cache

     目录          0  2007-06-19 00:08  Pixysoft.Office\obj\Debug\TempPE

     目录          0  2007-06-19 00:08  Pixysoft.Office\obj\Debug

     文件        236  2007-06-05 15:49  Pixysoft.Office\obj\Pixysoft.Office.csproj.FileList.txt

     目录          0  2007-06-18 20:39  Pixysoft.Office\obj

     文件       3225  2007-05-30 22:43  Pixysoft.Office\Pixysoft.Office.csproj

     文件        455  2007-05-30 22:43  Pixysoft.Office\Pixysoft.Office.csproj.user

     文件       1333  2007-05-30 22:43  Pixysoft.Office\Properties\AssemblyInfo.cs

     目录          0  2007-06-19 00:08  Pixysoft.Office\Properties

     文件       1375  2007-05-30 22:43  Pixysoft.Office\WordBookMark\WordBookMarks.cs

     目录          0  2007-06-19 00:08  Pixysoft.Office\WordBookMark

     文件      16027  2007-05-30 22:43  Pixysoft.Office\WordDocuments.cs

     文件       6902  2007-05-30 22:43  Pixysoft.Office\Wordparagraph\WordParagraphFormat.cs

     目录          0  2007-06-19 00:08  Pixysoft.Office\Wordparagraph

     文件       8324  2007-05-30 22:43  Pixysoft.Office\WordTable\WordTable.cs

     文件       3599  2007-05-30 22:43  Pixysoft.Office\WordTable\WordTableFormat.cs

     目录          0  2007-06-19 00:08  Pixysoft.Office\WordTable

............此处省略4个文件信息

评论

共有 条评论