1 基础:
(1) 在页面上引入华表对象:
- <OBJECT id=CellWeb1 height=220 width=700 classid=clsid:3F166327-8030-4881-8BD2-EA25350E574A VIEWASTEXT>
- <PARAM NAME="_Version" VALUE="65536">
- <PARAM NAME="_ExtentX" VALUE="18521">
- <PARAM NAME="_ExtentY" VALUE="7408">
- <PARAM NAME="_StockProps" VALUE="0">
- </OBJECT>
注释:(1) <OBJECT>标记用来包含对象。还有几个属性:align=值(left,right,center),hspace=值,vspace=值。
(2) <PARAM>为该对象的属性,用来给属性设置默认值。
(3) 通过上面的方式就加载了华表插件,有默认的行和列。另外可以在页面onload方法中设置华表的行和列.
(4) 在javascript语言中可以通过document.[formName.]CellWeb1来得到一个华表对象。
2 操作华表对象的一些方法:
CellWeb1.GetCurrentCol() 得到光标在华表中列坐标
CellWeb1.GetCurrentRow() 得到光标在华表中行坐标
CellWeb1.SetCellString(col,row,page,"单元格的值"); 设置第page页第col列,第row行单元格的内容
CellWeb1.GetCellString(col,row,page) 得到第page页第col列,第row行单元格的内容
CellWeb1.setRows(row,page) 设置第page页华表的行数
CellWeb1.setCols(col,page) 设置第page页华表的列数
CellWeb1.redraw() 可以理解为重新加载华表
(a) 在华表中设置一个按钮:
CellWeb1.SetButtonCell(col,row,0,buttonName,params,showValue,buttonPattrn);
注释:(1)params的值有:0:无动作
1:执行程序
2:弹出信息
(2)showValue:当params的值为2时,弹出的信息
(3)buttonPattrn有两种情形.为1时表示按钮只占单元格的一半,非1时则充满单元格
(b) 设置单选按钮:
CellWeb1.SetRadioCell(col,row,0,radioName+'\r\n');
注释: (1) radioName:是显示在华表中可见的数据,radio的实际值是多少(还有待了解)
(2) 在最后必须以回车换行结束,单选按钮之间用回车换行来分隔
(c)设置下拉框
CellWeb1.SetDroplistCell(col,row, 0, listValue+'\r\n',pattrn);
注释:(1) 下拉框的多个值都由回车换行隔开
(2) pattrn的值小于4时将显示下来三角标识,大于等于4时,下拉标识隐藏
(d)插入条形码
CellWeb1.SetBarCodeCell(col,row, 0, bc.options(bc.selectedIndex).value, backValue, pad, pad, pad, pad);
注释:(1) pad:条形码在单元格中离上下左右的距离
(2) backValue:双击条形码显示的内容(条形码说明)
(3) options值:
- <OPTION value="1">UPCA</OPTION>
- <OPTION value="2">UPCE</OPTION>
- <OPTION value="3">EAN13</OPTION>
- <OPTION value="4">EAN8</OPTION>
- <OPTION value="5">INTER25</OPTION>
- <OPTION value="6">CODE39</OPTION>
- <OPTION value="7">JAN</OPTION>
- <OPTION value="8">PDF417</OPTION>
- <OPTION value="9">CODE11</OPTION>
- <OPTION value="10">CODEBAR</OPTION>
(e)设置华表的背景图片
CellWeb1.SetBackImage(n,bgstyle.options(bgstyle.selectedIndex).value,0)
注释:(1) 当重复调用该函数n+1次时,该函数才能够生效
(2) bgstyle.options(bgstyle.selectedIndex).value是图片的三种显示方式的选择(0:平铺 1:居中 2:拉伸)
(3) 参数1是固定参数
(f)加载图片
CellWeb1.AddImage(bgurl.value);
注释:(1) bgurl是:<input type=file size=7 name=bgurl value="">
3 页方法
(1) CellWeb1.GetTotalSheets() 获得总页数
(2) CellWeb1.openFile("../file/订单运费表.cll",""); 打开一个华表文件
(3) CellWeb1.SetColWidth(1,60,12,0); 设置华表宽
(3) CellWeb1.InsertSheet(1,tp); 插入tp页数
(4) CellWeb1.GetCurSheet() 获得当前页 SetCurSheet(page);
(5) CellWeb1.ShowSheetLabel(falg,document.getElementById("CellWeb1").GetCurSheet()); 页标签
falg=1:显示页标签 falg=0:隐藏页标签
(6) CellWeb1.ShowTopLabel(falg,document.getElementById("CellWeb1").GetCurSheet());//列标签
falg=1:显示列标签 falg=0:隐藏列标签
(7) CellWeb1.ShowsideLabel(falg,document.getElementById("CellWeb1").GetCurSheet());//行标签
falg=1:显示行标签 falg=0:隐藏行标签
(8) CellWeb1.ShowVScroll(falg,document.getElementById("CellWeb1").GetCurSheet());//列滚动条
falg=1:显示列滚动条 falg=0:隐藏列滚动条
(9) CellWeb1.ShowHScroll(falg,document.getElementById("CellWeb1").GetCurSheet());//行滚动条
falg=1:显示行滚动条 falg=0:隐藏行滚动条
(10)CellWeb1.ShowGridLine(falg,document.getElementById("CellWeb1").GetCurSheet());//表格线
falg=1:显示表格线 falg=0:隐藏表格线
(11)CellWeb1.ShowPageBreak(falg);//打印分界线
falg=1:显示打印分界线 falg=0:隐藏打印分界线
4 表的操作:
(1) CellWeb1.GetCurrentRow(); 获得光标所在的当前行
(2) CellWeb1.GetCurrentCol(); 获得光标所在的当前列
(3) CellWeb1.SetRows(rowValue,0) GetRows(页参数);
(4) CellWeb1.SetCols(colValue,0)
(5) CellWeb1.SetColWidth(1,w,document.getElementById("CellWeb1").GetCurrentCol(),0);//设置当前单元格所在列的宽
(6) CellWeb1.SetRowHeight(1,1,document.getElementById("CellWeb1").GetCurrentRow(),0);//设置当前单元格所在行的高
(7) CellWeb1.GetColWidth(1,col,0);
(8) CellWeb1.GetRowheight(1,row,0);
(9) CellWeb1.SetCellBackColor(-1,i,0,cellWeb.FindColorIndex(15790320,1));//设置表格第i行的背景色
(10)CellWeb1.MoveToCell(3,6);//将第3列第6行的单元格作为当前单元格
(11)CellWeb.InsertRow(addrow_where,addrownum,page);
(12)CellWeb.InsertCol(addcol_where,addcolnum,page);
5 套打演示
(1) DemoCell.D(i, j, 0, i * j); 给第0页第i列第j行的单元格赋值为i*j
(2) DemoCell.DeleteSheet(0, 1);
DemoCell.Invalidate(); 这两个函数一起来执行,清楚第0页表单上的数据
6 文件操作
(1) cellWeb.openfile("../file/资产负债表.cll",""); 加载华表文件
(2) cellWeb.SaveSheet(cellWeb.GetCurSheet()); 保存当前页码的内容
(3) cellWeb.ExportTextDlg(); 以文本形式导出
(4) cellWeb.ExportExcelDlg(); 以Excel形式导出
(5) cellWeb.ImportExcelDlg();
(6) cellWeb.ImportTextDlg();
CELL 报表制作脚本举例
<%@ page contentType="text/html;charset=GBK"%>
<%@ taglib uri="/tags/web-html" prefix="html"%>
<%@ taglib uri="/tags/web-tianhe" prefix="templates"%>
<%@ page import="java.math.BigDecimal"%>
<%@ page import="java.util.List"%>
<%@ page import="java.util.Map"%>
<%@ page import="java.util.Date"%>
<script language="Jscript">
function setfilename()
{
filen="jsp/hr/personnel/Personnelreport.cll";
return filen;
}
function filldata()
{
<%
List bodyList=(List)request.getAttribute("bodyList"); //表体数据
Map headTailMap=(Map)request.getAttribute("headTailMap"); //表头表尾数据
int len = bodyList.size();
String title= (String) headTailMap.get("title");//标题
String userName=(String)headTailMap.get("userName");//制表人
String date=(String)headTailMap.get("dateId");//制表时间
%>
sheet = <%=0%>;
content_col=1;
//设置某页行数
CellRpt.SetRows(<%=len+4+1%>,sheet);//设置某页行数(行数,页号)
CellRpt.SetCols(15,sheet);//设置某页列数(列数,页号)
CellRpt.PrintSetOrient(1);//设置进纸方式为横放
CellRpt.MergeCells(1,1,15,1);//将指定区域的单元格组合(区域起始点列号,行号,区域结束点列号,行号)
CellRpt.SetCellFontStyle(1,1,sheet,2);//设置指定单元格的字体风格(列号,行号,页号,字体风格)
CellRpt.SetCellFontSize(1,1,sheet,20);//设置单元格字体大小(列号,行号,页号,字号)
CellRpt.SetCellAlign(1,1,sheet,36);//设置指定单元格的对齐方式(列号,行号,页号,参数)
CellRpt.S(1,1,sheet,"<%=title%>");
CellRpt.MergeCells(1,2,1,2);
CellRpt.SetCellFontStyle(1,2,sheet,3);
CellRpt.SetCellFontSize(1,2,sheet,10);
CellRpt.SetCellAlign(1,2,sheet,36);
CellRpt.S(1,2,sheet,"部门");
CellRpt.MergeCells(2,2,2,2);
CellRpt.SetCellFontStyle(2,2,sheet,3);
CellRpt.SetCellFontSize(2,2,sheet,10);
CellRpt.SetCellAlign(2,2,sheet,36);
CellRpt.S(2,2,sheet,"姓名");
CellRpt.MergeCells(3,2,3,2);
CellRpt.SetCellFontStyle(3,2,sheet,3);
CellRpt.SetCellFontSize(3,2,sheet,10);
CellRpt.SetCellAlign(3,2,sheet,36);
CellRpt.S(3,2,sheet,"性别");
CellRpt.MergeCells(4,2,4,2);
CellRpt.SetCellFontStyle(4,2,sheet,3);
CellRpt.SetCellFontSize(4,2,sheet,10);
CellRpt.SetCellAlign(4,2,sheet,36);
CellRpt.S(4,2,sheet,"年龄");
CellRpt.MergeCells(5,2,5,2);
CellRpt.SetCellFontStyle(5,2,sheet,3);
CellRpt.SetCellFontSize(5,2,sheet,10);
CellRpt.SetCellAlign(5,2,sheet,36);
CellRpt.S(5,2,sheet,"政治面貌");
CellRpt.MergeCells(6,2,6,2);
CellRpt.SetCellFontStyle(6,2,sheet,3);
CellRpt.SetCellFontSize(6,2,sheet,10);
CellRpt.SetCellAlign(6,2,sheet,36);
CellRpt.S(6,2,sheet,"学历");
CellRpt.MergeCells(7,2,7,2);
CellRpt.SetCellFontStyle(7,2,sheet,3);
CellRpt.SetCellFontSize(7,2,sheet,10);
CellRpt.SetCellAlign(7,2,sheet,36);
CellRpt.S(7,2,sheet,"专业技术名称");
CellRpt.MergeCells(8,2,8,2);
CellRpt.SetCellFontStyle(8,2,sheet,3);
CellRpt.SetCellFontSize(8,2,sheet,10);
CellRpt.SetCellAlign(8,2,sheet,36);
CellRpt.S(8,2,sheet,"职业技能名称");
CellRpt.MergeCells(9,2,9,2);
CellRpt.SetCellFontStyle(9,2,sheet,3);
CellRpt.SetCellFontSize(9,2,sheet,10);
CellRpt.SetCellAlign(9,2,sheet,36);
CellRpt.S(9,2,sheet,"出生日期");
CellRpt.MergeCells(10,2,10,2);
CellRpt.SetCellFontStyle(10,2,sheet,3);
CellRpt.SetCellFontSize(10,2,sheet,10);
CellRpt.SetCellAlign(10,2,sheet,36);
CellRpt.S(10,2,sheet,"入职时间");
CellRpt.MergeCells(11,2,11,2);
CellRpt.SetCellFontStyle(11,2,sheet,3);
CellRpt.SetCellFontSize(11,2,sheet,10);
CellRpt.SetCellAlign(11,2,sheet,36);
CellRpt.S(11,2,sheet,"家庭地址");
CellRpt.MergeCells(12,2,12,2);
CellRpt.SetCellFontStyle(12,2,sheet,3);
CellRpt.SetCellFontSize(12,2,sheet,10);
CellRpt.SetCellAlign(12,2,sheet,36);
CellRpt.S(12,2,sheet,"办公电话");
CellRpt.MergeCells(13,2,13,2);
CellRpt.SetCellFontStyle(13,2,sheet,3);
CellRpt.SetCellFontSize(13,2,sheet,10);
CellRpt.SetCellAlign(13,2,sheet,36);
CellRpt.S(13,2,sheet,"移动电话");
CellRpt.MergeCells(14,2,14,2);
CellRpt.SetCellFontStyle(14,2,sheet,3);
CellRpt.SetCellFontSize(14,2,sheet,10);
CellRpt.SetCellAlign(14,2,sheet,36);
CellRpt.S(14,2,sheet,"员工状态");
content_row=3;
<%
BigDecimal sumEmpNum = new BigDecimal(bodyList.size());
for(int i = 0;i < bodyList.size();i++){
Map bodyMap = (Map) bodyList.get(i);
String orgName = (String)bodyMap.get("ORGAN_NAME");//部门
String empName = (String)bodyMap.get("EMP_NAME");//员工姓名
String sex = (String)bodyMap.get("SEX");//性别
String policital = (String)bodyMap.get("POLICITAL_STATUS");//政治面貌
String edu = (String)bodyMap.get("EDUCATION");//学历
String tName = (String)bodyMap.get("NAME");//专业技术名称
String skillName = (String)bodyMap.get("SKILL_POST_NAME");//职业技能名称
String birthday = (String)bodyMap.get("BIRTHDAY");//生日
String entryDay = (String)bodyMap.get("ENTRY_ENTERPRISE_DAT");//入职时间
String addr = (String)bodyMap.get("ADDRESS");//家庭住址
String officePhone = (String)bodyMap.get("OFFICE_PHONE");//办公电话
String mobilePhone = (String)bodyMap.get("MOBILE_PHONE");//移动电话
String state = (String)bodyMap.get("STATE");//员工状态
String ageStr = "";
if(sex == null || "".equals(sex)){
sex = "";
}else{
switch(Integer.parseInt(sex)){
case 0 : sex="男";break;
case 1 : sex="女";break;
}
}
if(policital == null || "".equals(policital)){
policital = "";
}else{
switch(Integer.parseInt(policital)){
case 1 : policital="工人";break;
case 2 : policital="农民";break;
case 3 : policital="知识分子";break;
case 4 : policital="群众";break;
}
}
if(edu == null || "".equals(edu)){
edu = "";
}else{
switch(Integer.parseInt(edu)){
case 1 : edu="小学";break;
case 2 : edu="初中";break;
case 3 : edu="高中";break;
case 4 : edu="大学专科";break;
case 5 : edu="大学本科";break;
case 6 : edu="硕士";break;
case 7 : edu="博士";break;
}
}
if(skillName == null || "".equals(skillName)){
skillName = "";
}else{
switch(Integer.parseInt(skillName)){
case 1 : skillName="企业人力资源管理";break;
case 2 : skillName="计算机操作";break;
case 3 : skillName="仓储工";break;
case 4 : skillName="企业经营管理";break;
case 5 : skillName="秘书";break;
case 6 : skillName="物流管理";break;
case 7 : skillName="卷烟商品营销";break;
case 8 : skillName="客户服务管理";break;
case 9 : skillName="企业信息管理";break;
case 10 : skillName="汽车驾驶";break;
case 11 : skillName="营业员";break;
}
}
if(birthday == null || "".equals(birthday)){
birthday = "";
}else{
String yearBir = birthday.substring(0,4);
String dateNow = new Date().toString();
String yearNow = dateNow.substring(dateNow.length()-4,dateNow.length());
int ageInt = Integer.parseInt(yearNow) - Integer.parseInt(yearBir);
ageStr = String.valueOf(ageInt);
}
%>
content_col=1;
CellRpt.SetCellFontSize(content_col,content_row,sheet,10);
CellRpt.SetCellAlign(content_col,content_row,sheet,33);
CellRpt.S(content_col,content_row,sheet,"<%=orgName%>");
content_col++;
CellRpt.SetCellFontSize(content_col,content_row,sheet,10);
CellRpt.SetCellAlign(content_col,content_row,sheet,33);
CellRpt.S(content_col,content_row,sheet,"<%=empName%>");
content_col++;
CellRpt.SetCellFontSize(content_col,content_row,sheet,10);
CellRpt.SetCellAlign(content_col,content_row,sheet,33);
CellRpt.S(content_col,content_row,sheet,"<%=sex%>");
content_col++;
CellRpt.SetCellFontSize(content_col,content_row,sheet,10);
CellRpt.SetCellAlign(content_col,content_row,sheet,34);
CellRpt.S(content_col,content_row,sheet,"<%=ageStr%>");
content_col++;
CellRpt.SetCellFontSize(content_col,content_row,sheet,10);
CellRpt.SetCellAlign(content_col,content_row,sheet,34);
CellRpt.S(content_col,content_row,sheet,"<%=policital%>");
content_col++;
CellRpt.SetCellFontSize(content_col,content_row,sheet,10);
CellRpt.SetCellAlign(content_col,content_row,sheet,34);
CellRpt.S(content_col,content_row,sheet,"<%=edu%>");
content_col++;
CellRpt.SetCellFontSize(content_col,content_row,sheet,10);
CellRpt.SetCellAlign(content_col,content_row,sheet,34);
CellRpt.S(content_col,content_row,sheet,"<%=tName%>");
content_col++;
CellRpt.SetCellFontSize(content_col,content_row,sheet,10);
CellRpt.SetCellAlign(content_col,content_row,sheet,34);
CellRpt.S(content_col,content_row,sheet,"<%=skillName%>");
content_col++;
CellRpt.SetCellFontSize(content_col,content_row,sheet,10);
CellRpt.SetCellAlign(content_col,content_row,sheet,34);
CellRpt.S(content_col,content_row,sheet,"<%=birthday%>");
content_col++;
CellRpt.SetCellFontSize(content_col,content_row,sheet,10);
CellRpt.SetCellAlign(content_col,content_row,sheet,34);
CellRpt.S(content_col,content_row,sheet,"<%=entryDay%>");
content_col++;
CellRpt.SetCellFontSize(content_col,content_row,sheet,10);
CellRpt.SetCellAlign(content_col,content_row,sheet,34);
CellRpt.S(content_col,content_row,sheet,"<%=addr%>");
content_col++;
CellRpt.SetCellFontSize(content_col,content_row,sheet,10);
CellRpt.SetCellAlign(content_col,content_row,sheet,34);
CellRpt.S(content_col,content_row,sheet,"<%=officePhone%>");
content_col++;
CellRpt.SetCellFontSize(content_col,content_row,sheet,10);
CellRpt.SetCellAlign(content_col,content_row,sheet,34);
CellRpt.S(content_col,content_row,sheet,"<%=mobilePhone%>");
content_col++;
CellRpt.SetCellFontSize(content_col,content_row,sheet,10);
CellRpt.SetCellAlign(content_col,content_row,sheet,34);
CellRpt.S(content_col,content_row,sheet,"<%=state%>");
content_row++;
<%
}
%>
content_col=1;
CellRpt.MergeCells(content_col,content_row,content_col,content_row);
CellRpt.SetCellFontStyle(content_col,content_row,sheet,0);
CellRpt.SetCellAlign(content_col,content_row,sheet,33);
CellRpt.S(content_col,content_row,sheet,"合计");
content_col++;
CellRpt.SetCellFontSize(content_col,content_row,sheet,10);
CellRpt.SetCellAlign(content_col,content_row,sheet,34);
CellRpt.S(content_col,content_row,sheet,"<%=sumEmpNum%>(人)");//总人数
content_row++;
CellRpt.MergeCells(1,content_row,3,content_row);
CellRpt.SetCellFontSize(1,content_row,sheet,10);
CellRpt.SetCellAlign(1,content_row,sheet,33);
CellRpt.S(1,content_row,sheet,"制表人:"+"<%=userName%>");
CellRpt.MergeCells(12,content_row,14,content_row);
CellRpt.SetCellFontSize(12,content_row,sheet,10);
CellRpt.SetCellAlign(12,content_row,sheet,34);
CellRpt.S(12,content_row,sheet,"制表日期:"+"<%=date%>");
var line_rowBegin=2; //从第二行开始
var line_rowEnd=CellRpt.getRows(sheet)-2; //画到倒数第三行
var line_colBegin=1; //从第一列开始
var line_colEnd=CellRpt.getCols(sheet);//画到最后一列
CellRpt.DrawGridLine(line_colBegin, line_rowBegin, line_colEnd,line_rowEnd, 0, 2,-1);//所有框画细线
//打印设置
CellRpt.PrintRange(1,1,CellRpt.getCols(sheet),CellRpt.getRows(sheet));
CellRpt.PrintSetTopTitle(1,6);
CellRpt.PrintSetBottomTitle(content_row+1,content_row+1);
CellRpt.PrintSetOrient(1);//打印方向:1为横向,0为纵向
}
</script>