• 大小: 3.03MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-11-15
  • 语言: ASP
  • 标签: Aspose.Words  

资源简介

.net 中导出word的工具。Aspose.Word 导出到word、pdf

资源截图

代码片段和文件信息

/* ==============================================================================
   * 文 件 名:Program
   * 功能描述:
   * Copyright (c) 2013 武汉经纬视通科技有限公司
   * 创 建 人: alone
   * 创建时间: 2013/4/2 11:16:19
   * 修 改 人: 
   * 修改时间: 
   * 修改描述: 
   * 版    本: v1.0.0.0
   * ==============================================================================*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Regularexpressions;
using Aspose.Words;
namespace WordDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            var dic = new Dictionary();
            dic.Add(“姓名“ “杨幂“);
            dic.Add(“学历“ “本科“);
            dic.Add(“联系方式“ “02759597666“);
            dic.Add(“邮箱“ “304885433@qq.com“);
            dic.Add(“头像“ “.//1.jpg“);
            //使用书签操作
            Document doc = new Document(“.//1.doc“);
            DocumentBuilder builder = new DocumentBuilder(doc);
            foreach (var key in dic.Keys)
            {
                builder.MoveToBookmark(key);
                if (key != “头像“)
                {
                    builder.Write(dic[key]);
                }
                else
                {
                    builder.InsertImage(dic[key]);
                }
            }
            doc.Save(“书签操作.doc“);//也可以保存为1.doc 兼容03-07
            Console.WriteLine(“已经完成书签操作“);
            //使用特殊字符串替换
            doc = new Document(“.//2.doc“);
            foreach (var key in dic.Keys)
            {
                if (key != “头像“)
                {
                    var repStr = string.Format(“&{0}&“ key);
                    doc.Range.Replace(repStr dic[key] false false);
                }
                else
                {
                    Regex reg = new Regex(“&头像&“);
                    doc.Range.Replace(reg new ReplaceAndInsertImage(“.//1.jpg“) false);
                }
            }
            doc.Save(“字符串替换操作.doc“);//也可以保存为1.doc 兼容03-07
            Console.WriteLine(“已经完成特殊字符串替换操作“);
            Console.ReadKey();
        }
    }

    public class ReplaceAndInsertImage : IReplacingCallback
    {
        /// 
        /// 需要插入的图片路径
        /// 

        public string url { get; set; }

        public ReplaceAndInsertImage(string url)
        {
            this.url = url;
        }

        public ReplaceAction Replacing(ReplacingArgs e)
        {
            //获取当前节点
            var node = e.MatchNode;
            //获取当前文档
            Document doc = node.Document as Document;
            DocumentBuilder builder = new DocumentBuilder(doc);
            //将光标移动到指定节点
            builder.MoveTo(node);
            //插入图片
            builder.InsertImage(url);
            return ReplaceAction.Replace;
        }
    }


}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2013-04-02 10:37  WordDemo\
     目录           0  2013-04-02 11:17  WordDemo\WordDemo\
     文件         914  2013-04-02 10:37  WordDemo\WordDemo.sln
     文件       18432  2013-04-02 11:26  WordDemo\WordDemo.v11.suo
     文件     4007424  2013-04-02 10:38  WordDemo\WordDemo\Aspose.Words.dll
     目录           0  2013-04-02 10:38  WordDemo\WordDemo\bin\
     目录           0  2013-04-02 12:04  WordDemo\WordDemo\bin\Debug\
     文件       26624  2013-04-02 11:14  WordDemo\WordDemo\bin\Debug\1.doc
     文件       76607  2013-04-02 11:15  WordDemo\WordDemo\bin\Debug\1.jpg
     文件       26624  2013-04-02 11:31  WordDemo\WordDemo\bin\Debug\2.doc
     文件     4007424  2013-04-02 10:38  WordDemo\WordDemo\bin\Debug\Aspose.Words.dll
     文件        6656  2013-04-02 12:03  WordDemo\WordDemo\bin\Debug\WordDemo.exe
     文件       13824  2013-04-02 12:03  WordDemo\WordDemo\bin\Debug\WordDemo.pdb
     文件       21464  2013-04-02 10:58  WordDemo\WordDemo\bin\Debug\WordDemo.vshost.exe
     目录           0  2013-04-02 10:38  WordDemo\WordDemo\bin\Release\
     目录           0  2013-04-02 10:37  WordDemo\WordDemo\obj\
     目录           0  2013-04-02 12:03  WordDemo\WordDemo\obj\Debug\
     文件        5943  2013-04-02 11:17  WordDemo\WordDemo\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     目录           0  2013-04-02 10:37  WordDemo\WordDemo\obj\Debug\TempPE\
     文件         433  2013-04-02 12:03  WordDemo\WordDemo\obj\Debug\WordDemo.csproj.FileListAbsolute.txt
     文件        8877  2013-04-02 12:03  WordDemo\WordDemo\obj\Debug\WordDemo.csprojResolveAssemblyReference.cache
     文件        6656  2013-04-02 12:03  WordDemo\WordDemo\obj\Debug\WordDemo.exe
     文件       13824  2013-04-02 12:03  WordDemo\WordDemo\obj\Debug\WordDemo.pdb
     文件        3208  2013-04-02 11:44  WordDemo\WordDemo\Program.cs
     目录           0  2013-04-02 10:38  WordDemo\WordDemo\Properties\
     文件        1354  2013-04-02 10:37  WordDemo\WordDemo\Properties\AssemblyInfo.cs
     文件        2634  2013-04-02 11:28  WordDemo\WordDemo\WordDemo.csproj

评论

共有 条评论