给web添加一个dll引用:Apose.Words

下载链接:http://yunpan.cn/cA7v6uceM6KVw  提取码 11df

在Global.asax里面的Application_Start方法添加:

            License lic = new License();
string licPath = HttpContext.Current.Server.MapPath("/Plugs/Aspose.Words.lic");
lic.SetLicense(licPath);

添加完成后,会报错,把里面的应用换成

using Aspose.Words;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;

在Web下面添加一个文件夹Plugs,里面有两个文件:

http://yunpan.cn/cfQ6H5VJ7w8DC  提取码 ef95

设置一个按钮:

<input type="button" name="button" id="Report" value="批量打印" />

给按钮绑定事件:

 $("#Report").click(function () {
window.open("../../Apose/StudentInfo.aspx?studentType=" + $("#selStudentType").val() + "&schoolCode=" + $("#selSchool").val() + "&district=" + $("#selDistrict").val());
});
StudentInfo.aspx 页面就是导出的页面了,后台代码:
        protected void Page_Load(object sender, EventArgs e)
{
string schoolCode = Request.QueryString["schoolCode"].ToString();
string studentType = Request.QueryString["studentType"].ToString();
string district = Request.QueryString["district"].ToString();
print(schoolCode, studentType, district);
} DataTable getDs(string schoolCode, string studentType, string district)
{
string strWhere = " 1=1";
if (!string.IsNullOrEmpty(studentType))
{
strWhere += " and TypeCode='" + studentType + "'";
Session["TypeCode"] = studentType;
}
if (!string.IsNullOrEmpty(schoolCode))
{
strWhere += " and PrimarySchoolCode ='" + schoolCode + "'"; }
if (!string.IsNullOrEmpty(district))
{
strWhere += " and DistrictCode='" + district + "'";
}
DataTable dt = new BLL.ObjMethod().GetList("View_CryStudent", strWhere);
return dt;
} protected void print(string schoolCode, string studentType, string district)
{
Document doc = new Document();
DocumentBuilder docBuilder = new DocumentBuilder(doc); Document src = null; var dt = getDs(schoolCode, studentType, district);
int count = dt.Rows.Count;
show.Text = "预备打印学生数量为:"+count;
DataRow dr;
for (int i = ; i < dt.Rows.Count; i++)
{
dr = dt.Rows[i];
if (dr["TypeCode"].ToString() == "")
{
src = new Document(Server.MapPath("/files/1.doc"));
}
if (dr["TypeCode"].ToString() == "")
{
src = new Document(Server.MapPath("/files/10.doc"));
}
src.Range.Replace("<Ф1Ф>", dr["Name"].ToString(), false, false);
src.Range.Replace("<Ф2Ф>", dr["SexCode"].ToString(), false, false);
src.Range.Replace("<Ф3Ф>", dr["Birthday2"].ToString(), false, false);
src.Range.Replace("<Ф4Ф>", dr["Nation"].ToString(), false, false);
src.Range.Replace("<Ф5Ф>", dr["EduId"].ToString(), false, false);
src.Range.Replace("<Ф6Ф>", dr["RollId"].ToString(), false, false);
src.Range.Replace("<Ф7Ф>", dr["CardID"].ToString(), false, false);
src.Range.Replace("<Ф8Ф>", dr["HuKouName"].ToString() + dr["HukouAddress"].ToString(), false, false);
src.Range.Replace("<Ф9Ф>", dr["HuZhuName"].ToString(), false, false);
src.Range.Replace("<Ф10Ф>", dr["HuZhuRelationName"].ToString(), false, false);
src.Range.Replace("<Ф11Ф>", dr["IsAllFamilyIn"].ToString(), false, false);
string relation = dr["IsAllFamilyIn"].ToString();
if (relation == "父户口同在")
{
src.Range.Replace("<Ф12Ф>", dr["Father"].ToString(), false, false);
}
else if (relation == "母户口同在")
{
src.Range.Replace("<Ф12Ф>", dr["Mother"].ToString(), false, false);
}
else if (relation == "父母户口同在")
{
src.Range.Replace("<Ф12Ф>", dr["Father"].ToString() + "," + dr["Mother"].ToString(), false, false);
}
else {
src.Range.Replace("<Ф12Ф>","", false, false);
} src.Range.Replace("<Ф13Ф>", dr["HouseQuXianAddressName"].ToString() + dr["HouseAddress"].ToString(), false, false);
src.Range.Replace("<Ф14Ф>", dr["HouseOwnerName"].ToString(), false, false);
src.Range.Replace("<Ф15Ф>", dr["HouseOwnerRelationName"].ToString(), false, false);
src.Range.Replace("<Ф16Ф>", dr["HouseOwnerCardID"].ToString(), false, false);
src.Range.Replace("<Ф17Ф>", dr["Tenantry"].ToString(), false, false);
src.Range.Replace("<Ф18Ф>", dr["GuardianName1"].ToString(), false, false);
src.Range.Replace("<Ф19Ф>", dr["GuardianRelationName1"].ToString(), false, false);
src.Range.Replace("<Ф20Ф>", dr["GuardianZhengZhi1"].ToString(), false, false);
src.Range.Replace("<Ф21Ф>", dr["GuardianEduCode1"].ToString(), false, false);
src.Range.Replace("<Ф22Ф>", dr["GuardianCompany1"].ToString(), false, false);
src.Range.Replace("<Ф23Ф>", dr["GuardianTelephone1"].ToString(), false, false);
src.Range.Replace("<Ф24Ф>", dr["GuardianName2"].ToString(), false, false);
src.Range.Replace("<Ф25Ф>", dr["GuardianRelationName2"].ToString(), false, false);
src.Range.Replace("<Ф26Ф>", dr["GuardianZhengZhi2"].ToString(), false, false);
src.Range.Replace("<Ф27Ф>", dr["GuardianEduCode2"].ToString(), false, false);
src.Range.Replace("<Ф28Ф>", dr["GuardianCompany2"].ToString(), false, false); src.Range.Replace("<Ф29Ф>", dr["GuardianTelephone2"].ToString(), false, false);
src.Range.Replace("<Ф30Ф>", dr["xh"].ToString(), false, false);
src.Range.Replace("<Ф31Ф>", dr["Name"].ToString(), false, false);
src.Range.Replace("<Ф32Ф>", dr["TiJiaoNumber"].ToString(), false, false);
src.Range.Replace("<Ф33Ф>", dr["PrimarySchoolName"].ToString(), false, false); if (dr["TypeCode"].ToString() == "")
{
src.Range.Replace("<Ф34Ф>", dr["JieDuTypeName"].ToString(), false, false);
} InsertDocument(doc.LastSection.Body.LastParagraph, src);
docBuilder.MoveToDocumentEnd();
docBuilder.InsertBreak(BreakType.PageBreak);
jindu.Text = "已经准备学生数量:"+(i+);
}
// string path = "/files/" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".pdf";
string path = "/files/" + "啊啊啊" + ".pdf";
doc.Save(Server.MapPath(path), SaveFormat.Pdf);
download(path);
msg.InnerHtml = "<a href=\""+ path +"\">如果您没有正常打开文件,请点击这里</a>"; } /// <summary>
/// Inserts content of the external document after the specified node.
/// Section breaks and section formatting of the inserted document are ignored.
/// </summary>
/// <param name="insertAfterNode">Node in the destination document after which the content
/// should be inserted. This node should be a block level node (paragraph or table).</param>
/// <param name="srcDoc">The document to insert.</param>
static void InsertDocument(Node insertAfterNode, Document srcDoc)
{
// Make sure that the node is either a paragraph or table.
if ((!insertAfterNode.NodeType.Equals(NodeType.Paragraph)) &
(!insertAfterNode.NodeType.Equals(NodeType.Table)))
throw new ArgumentException("The destination node should be either a paragraph or table."); // We will be inserting into the parent of the destination paragraph.
CompositeNode dstStory = insertAfterNode.ParentNode; // This object will be translating styles and lists during the import.
NodeImporter importer = new NodeImporter(srcDoc, insertAfterNode.Document, ImportFormatMode.KeepSourceFormatting); // Loop through all sections in the source document.
foreach (Section srcSection in srcDoc.Sections)
{
// Loop through all block level nodes (paragraphs and tables) in the body of the section.
foreach (Node srcNode in srcSection.Body)
{
// Let's skip the node if it is a last empty paragraph in a section.
if (srcNode.NodeType.Equals(NodeType.Paragraph))
{
Paragraph para = (Paragraph)srcNode;
if (para.IsEndOfSection && !para.HasChildNodes)
continue;
} // This creates a clone of the node, suitable for insertion into the destination document.
Node newNode = importer.ImportNode(srcNode, true); // Insert new node after the reference node.
dstStory.InsertAfter(newNode, insertAfterNode);
insertAfterNode = newNode;
}
}
}
private void download(string filePath)
{
Response.Redirect(filePath);
}
//private void download(string filePath)
//{
// #region default value // //查看方式,作为附件下载还是在浏览器中打开。默认为附件下载。浏览器中打开:viewType="inline";
// string viewType = "attachment"; // //下载完成是否删除,默认不删除。
// bool toDelete = false; // //内容类型,不同文件格式的内容类型不同。
// string contentType = "application/pdf"; // //文件保存时的默认名称。
// string fileName = "print.pdf"; // //要下载的文件
// //string filePath = "/files/student.docx"; // #endregion // //#region Reset value
// //HttpRequest httpRequest = HttpContext.Current.Request; // //if (!string.IsNullOrEmpty(httpRequest["viewType"]))
// // viewType = httpRequest["viewType"]; // //if (!string.IsNullOrEmpty(httpRequest["toDelete"]))
// // toDelete = httpRequest["toDelete"].ToLower() == "true"; // //if (!string.IsNullOrEmpty(httpRequest["filePath"]))
// // filePath = httpRequest["filePath"]; // //if (!string.IsNullOrEmpty(httpRequest["fileName"]))
// // fileName = httpRequest["fileName"]; // //if (!string.IsNullOrEmpty(httpRequest["contentType"]))
// // contentType = httpRequest["contentType"]; // //#endregion // filePath = HttpContext.Current.Server.MapPath(filePath); // Stream fileStream = null;
// bool fileExsits = File.Exists(filePath); // if (fileExsits)
// fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
// else
// return; // HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
// HttpContext.Current.Response.BufferOutput = false; // fileName = HttpUtility.UrlEncode(fileName, Encoding.UTF8).Replace('+', ' '); // HttpContext.Current.Response.Clear(); // HttpContext.Current.Response.AppendHeader("Content-Disposition", string.Format("{0};filename=\"{1}\"", viewType, fileName));
// HttpContext.Current.Response.AddHeader("Content-Length", fileStream.Length.ToString());
// HttpContext.Current.Response.ContentType = contentType; // try
// {
// long dataToRead = fileStream.Length;
// byte[] buffer;
// const int buffSize = 1024 * 16;
// int length = 0;
// while (dataToRead > 0)
// {
// if (HttpContext.Current.Response.IsClientConnected)
// {
// buffer = new Byte[buffSize];
// length = fileStream.Read(buffer, 0, buffSize);
// HttpContext.Current.Response.OutputStream.Write(buffer, 0, length);
// dataToRead = dataToRead - length;
// }
// else
// {
// dataToRead = -1;
// }
// }
// }
// finally
// {
// fileStream.Close();
// fileStream.Dispose();
// if (toDelete)
// {
// //new FileInfo(filePath).Attributes = FileAttributes.Normal;
// File.Delete(filePath);
// }
// } // HttpContext.Current.Response.End();
//}

word截图:

Apose 套打的更多相关文章

  1. bzoj1901--树状数组套主席树

    树状数组套主席树模板题... 题目大意: 给定一个含有n个数的序列a[1],a[2],a[3]--a[n],程序必须回答这样的询问:对于给定的i,j,k,在a[i],a[i+1],a[i+2]--a[ ...

  2. BZOJ 3110: [Zjoi2013]K大数查询 [树套树]

    3110: [Zjoi2013]K大数查询 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 6050  Solved: 2007[Submit][Sta ...

  3. 搭建一套自己实用的.net架构(3)续 【ORM Dapper+DapperExtensions+Lambda】

    前言 继之前发的帖子[ORM-Dapper+DapperExtensions],对Dapper的扩展代码也进行了改进,同时加入Dapper 对Lambda表达式的支持. 由于之前缺乏对Lambda的知 ...

  4. Linux Socket 原始套接字编程

    对于linux网络编程来说,可以简单的分为标准套接字编程和原始套接字编程,标准套接字主要就是应用层数据的传输,原始套接字则是可以获得不止是应用层的其他层不同协议的数据.与标准套接字相区别的主要是要开发 ...

  5. c 网络与套接字socket

    我们已经知道如何使用I/O与文件通信,还知道了如何让同一计算机上的两个进程进行通信,这篇文章将创建具有服务器和客户端功能的程序 互联网中大部分的底层网络代码都是用C语言写的. 网络程序通常有两部分组成 ...

  6. WebSocket异常 通常每个套接字地址(协议/网络地址/端口)只允许使用一次

    websocket的实例:http://blog.csdn.net/for_cxc/article/details/51500185 问题: 新建一个连接通信没有问题,但是如果关闭再建立就会报错:通常 ...

  7. 搭建一套自己实用的.net架构(3)【ORM-Dapper+DapperExtensions】

    现在成熟的ORM比比皆是,这里只介绍Dapper的使用(最起码我在使用它,已经运用到项目中,小伙伴们反馈还可以). 优点: 1.开源.轻量.小巧.上手容易. 2.支持的数据库还蛮多的, Mysql,S ...

  8. 【教程】CDQ套CDQ——四维偏序问题

    前言 上一篇文章已经介绍了简单的CDQ分治,包括经典的二维偏序和三维偏序问题,还有带修改和查询的二维/三维偏序问题.本文讲介绍多重CDQ分治的嵌套,即多维偏序问题. 四维偏序问题       给定N( ...

  9. Apache报错信息之通常每个套接字地址(协议/网络地址/端口)只允许使用一次(could not bind to address 0.0.0.0:80)

    我们常常在执行 httpd –k restart 重启Apache时报错提示: (OS 10048)通常每个套接字地址(协议/网络地址/端口)只允许使用一次.  : AH00072: make_soc ...

随机推荐

  1. TortoiseGit disconnected: no supported authentication methods available(server sent:publickey)

    之前一直用命令行,现在想用图形工具,TortoiseGit,安装后遇到错误 TortoiseGit disconnected: no supported authentication methods ...

  2. IOS 图片阴影,圆角等处理

    一直以来,为IOS添加图片的特殊效果都是通过跟美工的配合,比如,要加阴影,就从美工那边获得一张阴影效果图,在界面上画两个UIImageView,将阴影放在下面,图像放上上面,错开一定角度.有比如想做圆 ...

  3. nginx+tomcat动静分离的核心配置

    #所有jsp的页面均交由tomcat或resin处理 location ~ .(jsp|jspx|do)?$ { proxy_set_header Host $host; proxy_set_head ...

  4. 全局唯一ID的生成方式

    一.程序直接生成: 使用jdk中的concurrent包可以轻松实现唯一数字型ID的生成,且无需考虑单例.采用高效率的CAS无需考虑synchronized关键字 import java.util.c ...

  5. Android使用的开发MediaRecorder录制视频

    MediaRecorder除了使用录制音频.还可用于录制视频.关于MediaRecorder的具体解释大家能够參考<Android开发之MediaRecorder类具体解释>.使用Medi ...

  6. [015]staic成员及staic成员函数

    C++primer里面讲过:static成员它不像普通的数据成员,static数据成员独立于该类的任意对象而存在,每个static数据成员是与类关联的对象,并不与该类的对象相关联!这句话可能比较拗口, ...

  7. Routing and controllers

    Routing and controllers We will build a very simple inventory system to display our album collection ...

  8. Mybatis案例

    MyBatis MyBatis 是支持普通 SQL 查询,存储过程和高级映射的优秀持久层框架. MyBatis 消除了几乎所有的 JDBC 代码和参数的手工设置以及对结果集的检索. MyBatis 可 ...

  9. 命令行界面下用户和组管理之groupmod的使用

    NAME    groupmod - modify a group definition on the system SYNOPSIS       groupmod [options] GROUP O ...

  10. vim纯文本处理插件txtbrowser

    纯文本处理插件:txtBrowser 插件作者:http://guoyoooping.blog.163.com/ Github地址:https://github.com/vim-scripts/Txt ...