给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. 设计模式之十三:适配器模式(Adapter)

    适配器模式: 将一个类的接口转换成另外一个期望的类的接口.适配器同意接口互不兼容的类一起工作. Convert the interface of a class into another interf ...

  2. USB移动硬盘WinPE启动盘的制作方法

    USB移动硬盘WinPE启动盘的制作方法 软件:老九WinPE 老毛桃终于撒手无论版 发行时间:2007年9月11日 制作发行:老毛桃 作用:当系统坏了,无法进入时,用来做系统维护,备份文件.轻巧稳定 ...

  3. protocol buffer的简单使用

    protocol buffer是一个高效的结构化数据存储格式,用来结构化数据的序列化与反序列化.目前支持java.c++.Python 相对于json而言: 数据量跟小 其他的还没看出什么优势 下载地 ...

  4. [MODx] 7. MIGX DB

    MODx provides a really unfriendly way to work with xPDO class. What I means is you need to define XM ...

  5. iOS开发——数据持久化Swift篇&SettingBundle

    SettingBundle import UIKit class ViewController: UIViewController { var userDefault = NSUserDefaults ...

  6. React Editor 应用编辑器(1) - 拖拽功能剖析

    这是可视化编辑器 Gaea-Editor 的第一篇连载分析文章,希望我能在有限的篇幅讲清楚制作这个网页编辑器的动机,以及可能带来的美好使用前景(画大饼).它会具有如下几个特征: 运行在网页 文档流布局 ...

  7. 我的开发框架(WinForm)4

    日志模块 对于一个系统来说,日志模块是必不可少的,它能给后面系统的维护和bug的修复,带来极大的方便..net的日志模块有很多,比较流行的有Log4Net,NLog,还有微软企业库的日志模块,我采用的 ...

  8. C语言枚举

    应该是 各种语言都支持枚举的. 所以这个 之前在我们java案例里面就出现过的季节代码再次出现了. 枚举帮我们起到一个变量值,在某一范围内的限定,用来避免一些非法值的键入. 值得注意的是,这里面的枚举 ...

  9. vagrant yii2 Exception 'yii\db\Exception' with message 'SQLSTATE[HY000] [2002]

    开发环境:vangrant + LAMP 安装了yii2 advanced版本之后,通过url访问fornted 报数据库user表不存在,看了安装yii2 advanced的教程,里面说需要需要运行 ...

  10. CSS属性[text-overflow]使用问题

    text-overflow:clip | ellipsis 这个属性使用必须通过几个属性一块才能使用 1,overflow:hidden; 这个属性是内容区装不下内容应该怎么办.这里让溢出内容直接不显 ...