Apose 套打
给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 套打的更多相关文章
- bzoj1901--树状数组套主席树
树状数组套主席树模板题... 题目大意: 给定一个含有n个数的序列a[1],a[2],a[3]--a[n],程序必须回答这样的询问:对于给定的i,j,k,在a[i],a[i+1],a[i+2]--a[ ...
- BZOJ 3110: [Zjoi2013]K大数查询 [树套树]
3110: [Zjoi2013]K大数查询 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 6050 Solved: 2007[Submit][Sta ...
- 搭建一套自己实用的.net架构(3)续 【ORM Dapper+DapperExtensions+Lambda】
前言 继之前发的帖子[ORM-Dapper+DapperExtensions],对Dapper的扩展代码也进行了改进,同时加入Dapper 对Lambda表达式的支持. 由于之前缺乏对Lambda的知 ...
- Linux Socket 原始套接字编程
对于linux网络编程来说,可以简单的分为标准套接字编程和原始套接字编程,标准套接字主要就是应用层数据的传输,原始套接字则是可以获得不止是应用层的其他层不同协议的数据.与标准套接字相区别的主要是要开发 ...
- c 网络与套接字socket
我们已经知道如何使用I/O与文件通信,还知道了如何让同一计算机上的两个进程进行通信,这篇文章将创建具有服务器和客户端功能的程序 互联网中大部分的底层网络代码都是用C语言写的. 网络程序通常有两部分组成 ...
- WebSocket异常 通常每个套接字地址(协议/网络地址/端口)只允许使用一次
websocket的实例:http://blog.csdn.net/for_cxc/article/details/51500185 问题: 新建一个连接通信没有问题,但是如果关闭再建立就会报错:通常 ...
- 搭建一套自己实用的.net架构(3)【ORM-Dapper+DapperExtensions】
现在成熟的ORM比比皆是,这里只介绍Dapper的使用(最起码我在使用它,已经运用到项目中,小伙伴们反馈还可以). 优点: 1.开源.轻量.小巧.上手容易. 2.支持的数据库还蛮多的, Mysql,S ...
- 【教程】CDQ套CDQ——四维偏序问题
前言 上一篇文章已经介绍了简单的CDQ分治,包括经典的二维偏序和三维偏序问题,还有带修改和查询的二维/三维偏序问题.本文讲介绍多重CDQ分治的嵌套,即多维偏序问题. 四维偏序问题 给定N( ...
- Apache报错信息之通常每个套接字地址(协议/网络地址/端口)只允许使用一次(could not bind to address 0.0.0.0:80)
我们常常在执行 httpd –k restart 重启Apache时报错提示: (OS 10048)通常每个套接字地址(协议/网络地址/端口)只允许使用一次. : AH00072: make_soc ...
随机推荐
- C++中的new与delete总结
1. operator new.operator delete与new.delete操作符的区别: operator new的作用类似于malloc,负责分配内存:operator delete的作用 ...
- 教你如何选择Android游戏引擎
我们进行Android游戏开发时选择游戏引擎是必须的,但是该如何选择呢?哪个Android游戏引擎更加适合自己呢?本文就提供了三个游戏引擎的对比说明,阐述了它们各自的特点,为大家选择引擎提供了参照. ...
- android学习日记23--Android XML解析
一.简述 XML语言是跨平台,JAVA对XML语言支持得比较好,android系统的应用层平台是JAVA做的,所以用XML.XML解析比较简单.XML解析就是将获取到的数据分离出来,基本的网络数据传输 ...
- Shell脚本文件操作
Linux Shell http://baike.baidu.com/link?url=2LxUhKzlh5xBUgQrS0JEc61xi761nvCS7SHJsa1U1SkVbw3CC869AoUC ...
- C#解决微信支付Exception has been thrown by the target of an invocation(调用的目标发生了异常)的问题
今天搭建微信扫码支付环境的时候,一样的配置参数,调用连接提示错误 错误:调用的目标发生了异常 然后跟踪到执行 MD5 md5 = System.Security.Cryptography.MD5.Cr ...
- setTimeout和setImmediate以及process.nextTick的区别
在javascript中我们了解到了setTimeout和setInterVal函数事件队列(任务队列)的相关知识,除了setTimeout和setInterval这两个方法外,Node.js还提供了 ...
- 使用 Spring 2.5 基于注解驱动的 Spring MVC
http://www.ibm.com/developerworks/cn/java/j-lo-spring25-mvc/ 概述 继 Spring 2.0 对 Spring MVC 进行重大升级后,Sp ...
- asp:弹出警告框,并重定向的自定义过程
因为制作的需要写了这样一个简单的函数,重定向可以是指定的页.也可以是前一页! 有两个参数:messtr,警告框的信息;urlstr:转向的网页,为""时,返回到前一页! 程序代码 ...
- vs2010开发android的准备工作
安装 Mono for Android for Visual Studio 2010 需要下面4个步骤: 安装 JDK 安装 Android SDK 配置模拟器 安装 Mono for Android ...
- sqlserver的增删改查
select*from shuiguo 查询表 且小于等于7的范围) select distinct name from shuiguo--去除重复,只针对一列 select * from shui ...