给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. file_put_contents() failed to open stream: Permission denied 问题解决

    很长时间没有写PHP了,今天突然有个需求要写一个保存文件的功能. function downloadFile( $url , $savePath = '' ) {     $fileName = ge ...

  2. 使用Eclipse建立Maven的SpringMVC项目

    非常感谢博客的大神,让我成功地构建项目 http://limingnihao.iteye.com/blog/830409 但在依照这篇文章构建构建时遇到了一些问题,在这里总结一下: 问题一.2.3.2 ...

  3. How-to Dump Keys from Memcache--reference

    Submitted by Lars Windolf on 19. October 2012 - 21:53 http://lzone.de/dump%20memcache%20keys You spe ...

  4. CSS3——选项卡切换

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. iOS语言国际化

    参考网站:http://blog.sina.com.cn/s/blog_7b9d64af0101jncz.html   语言国际化:根据系统不同的语言自动切换 Xcode6.2   一.在不同语言下工 ...

  6. Objective-C,复合类,Composition

     复合类 5.复合类现实中,复杂的对象都是由较小和较为简单的对象构成:由简单对象创建复杂对象的过程称作合成.合成通常使用在有has-a关系的对象:通常的基本数据类型可以满足构造简单和小的对象.为了从小 ...

  7. 使用Keil建立工程和烧录到89C52板上

    又开始学习C51了,不清楚能坚持多久,之前学过一段时间,学完P1口就没再学了,之前学的都忘了. 1. 使用Keil 进行建立工程:打开Keil 4. 加载C文件进工程里面 然后展开"Sour ...

  8. 【linux操作命令】crontab

    带续写... 版权声明:本文为博主原创文章,未经博主允许不得转载.

  9. 读jQuery官方文档:样式

    样式 使用jQuery,无论是设置或者获取元素样式都十分简便. // 支持驼峰式和分割线式,两种方式等价(原生JavaScript只支持驼峰式) $('h1').css('fontSize'); $( ...

  10. 怎么关闭InstantRun

     Settings → Build, Execution, Deployment → Instant Run and uncheck Enable Instant Run.