下载demo源码地址
https://download.csdn.net/download/heqinghua217/10634224
华表打印源代码demo,包括华表的安装包,以及代码demo,打印仅仅支持ie,不需要引入任何jar包,简单还是挺简单的。api放在webroot下。一个word,一个自带的api
代码里封装了一个cellMan.js的工具类,方便调用,也可以不用工具类,自己写。
其实打印的东西一般都是固定格式,合并、加粗,都可以在工具中设置,如同excel操作
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!-- <link rel="stylesheet" type="text/css" href="styles.css"> -->
<script type='text/javascript' src='cell/cellMan.js'></script>
<script>
var cellM = new CELL();
var cellObj = null;
function initCell(){
cellObj = document.all("cell") ;//获得cell对象
cellM.register(cellObj) ;//登录注册,此方法自己做了封装
cellM.open(cellObj, 'test.cll') ;//打开自己生产的cll
cellObj.Border = 0;//这是边框
cellControl(cellM,cellObj);//给cell赋值
cellM.setReadOnly(cellObj, true) ;//设置cell只读
cellM.setCell(cellObj);//吧对象放入封装的cell管理类中
}
function cellControl(cellM,cellObj) {
//,第三列第五行插入 值,值是 成都小姐姐, 参数0表示 在第一个sheet页中的
cellM.cellObj.SetCellString(3,5,0, "成都小姐姐");
}
function doPrint(){
cellObj.PrintPara(-1, 1, 0, 0);//设置打印参数
cellObj.PrintSetPrintCopies(1);//打印页数
cellObj.PrintSheet(1,0);//得到当前sheet页
cellObj.PrintSheet(1,1);//得到当前sheet页
}
function prePrint(){
cellObj.PrintSetDefautPrinter();
cellObj.PrintPara(-1, 1, 0, 0);
cellObj.PrintPreviewEx(0,cellObj.GetCurSheet,false);
}
</script>
</head>
<body onLoad="initCell();">
<table cellpadding="0" cellspacing="0" border="0" height="100%" width="100%">
<tr>
<td align="center" valign="top" height="100%" width="100%">
<OBJECT codebase='cell/cellweb5.3.9.14.cab' classid="clsid:3F166327-8030-4881-8BD2-EA25350E574A"
id='cell' name="cell" style="width:100%;height:100%">
</OBJECT>
</td>
</tr>
<tr>
<td>
<input type="button" value="打印预览" onclick="prePrint();" />
<input type="button" value="打 印" onclick="doPrint();"/>
<input type="button" value="打印设置" onclick="cellM.printSetup(cellObj);"/>
<input type="button" value="关闭" onclick="window.close();"/>
</td>
</tr>
</table>
</body>
</html>