• 大小: 1.47MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-09-20
  • 语言: C#
  • 标签: word模板  C#  asp.net  

资源简介

C#asp.net通过word模板生成包含多页word文件

资源截图

代码片段和文件信息

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.Office.Interop.Word;

namespace TestApp
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender EventArgs e)
        {

        }

        protected void buttonstartup_Click(object sender EventArgs e)
        {
            Microsoft.Office.Interop.Word._Application appWord = new Microsoft.Office.Interop.Word.ApplicationClass();
            Microsoft.Office.Interop.Word._Document docFile = null;
            Microsoft.Office.Interop.Word._Document tempFile = null;

            this.Label1.Text = “生成开始时间“ + System.DateTime.Now.ToLongTimeString();
            try
            {
                
                appWord.Visible = false;
                object objTrue = true;
                object objFalse = false;
                object objTemplate = Server.MapPath(@“dot\\zshx.dot“);//模板路径
                object objkbTemplate = Server.MapPath(@“dot\\kbhx.dot“);//模板路径
                object objDocType = Microsoft.Office.Interop.Word.WdDocumentType.wdTypeDocument;
                tempFile = appWord.Documents.Add(ref objkbTemplate ref objFalse ref objDocType ref objTrue);

               
                object objTarget = WdMergeTarget.wdMergeTargetSelected;
                object objUseFormatFrom = WdUseFormattingFrom.wdFormattingFromSelected;
                object miss = System.Reflection.Missing.Value;
                object missingValue = Type.Missing;
                object doNotSaveChanges = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges;
                object confirmConversion = false;
                object link = false;
                object attachment = false;

                for (int i = 0; i < 100; i++)
                {
                    docFile = appWord.Documents.Add(ref objTemplate ref objFalse ref objDocType ref objTrue);
                    //第一步生成word文档
                    //定义书签变量
                    object obDD_Name = “DD_Name“;//姓 名
                    object obDD_Sex = “DD_Sex“;//性 别
                    object obDD_Age = “DD_Age“;//年龄
                    object obDD_Birthday = “DD_Birthday“; //出生年月
                    object obDD_Nation = “DD_Nation“; //民 族
                    object obDD_Native = “DD_Native“; //籍 贯

                    //第二步 读取数据,填充数据集
                    //SqlDataReader dr = XXXXX;//读取出来的数据集
                    //第三步 给书签赋值
                    //给书签赋值

                    // docFile.Bookmarks.get_Item(ref obDD_Name).Range.Text = “姓 名“; //姓 名
                    docFile.Bookmarks.get_Item(ref obDD_Sex).Range.Text = “性 别“ + i.ToString();

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2012-08-06 21:46  TestApp\
     目录           0  2012-08-06 21:46  TestApp\TestApp\
     文件         827  2012-08-07 14:39  TestApp\TestApp\Default.aspx
     文件        6199  2012-08-07 14:32  TestApp\TestApp\Default.aspx.cs
     文件        1993  2012-08-07 14:29  TestApp\TestApp\Default.aspx.designer.cs
     文件       20381  2012-08-07 08:31  TestApp\TestApp\ExportWord.cs
     目录           0  2012-08-06 21:46  TestApp\TestApp\Properties\
     文件        1332  2012-06-14 08:06  TestApp\TestApp\Properties\AssemblyInfo.cs
     文件        5035  2012-08-07 10:07  TestApp\TestApp\TestApp.csproj
     文件        1141  2012-08-07 10:07  TestApp\TestApp\TestApp.csproj.user
     文件        1246  2012-06-14 08:06  TestApp\TestApp\Web.config
     文件        8412  2012-08-07 10:05  TestApp\TestApp\WordDocumentMerger.cs
     文件       40766  2012-08-07 10:08  TestApp\TestApp\WordMLHelper.cs
     目录           0  2012-08-06 21:46  TestApp\TestApp\bin\
     文件       57344  2012-08-06 21:55  TestApp\TestApp\bin\Interop.VBIDE.dll
     文件      655360  2012-08-06 21:55  TestApp\TestApp\bin\Interop.Word.dll
     文件      662120  2007-10-10 09:48  TestApp\TestApp\bin\Microsoft.Office.Interop.Word.dll
     文件       36864  2012-08-07 14:33  TestApp\TestApp\bin\TestApp.dll
     文件       50688  2012-08-07 14:33  TestApp\TestApp\bin\TestApp.pdb
     目录           0  2012-08-06 21:46  TestApp\TestApp\dllapi\
     文件      970240  2012-06-14 08:09  TestApp\TestApp\dllapi\SMEntry.dll
     文件         234  2012-06-14 08:09  TestApp\TestApp\dllapi\SMEntry.ini
     文件      713723  2012-06-14 08:09  TestApp\TestApp\dllapi\SMEntry.map
     文件        7691  2012-06-14 08:09  TestApp\TestApp\dllapi\sqlConf.xml
     目录           0  2012-08-06 21:52  TestApp\TestApp\dot\
     文件       31232  2012-08-06 21:53  TestApp\TestApp\dot\123.dot
     文件       40081  2012-08-07 08:33  TestApp\TestApp\dot\AccEndReport.xml
     文件       60332  2012-08-07 08:33  TestApp\TestApp\dot\AccPlanTemplate.xml
     文件       48338  2012-08-07 08:33  TestApp\TestApp\dot\AccReport.xml
     文件       29768  2012-08-07 08:33  TestApp\TestApp\dot\AccReportContinue.xml
     文件       29458  2012-08-07 08:33  TestApp\TestApp\dot\AccReportInit.xml
............此处省略25个文件信息

评论

共有 条评论