在下面代码中如何给每个每个cell添加title属性,cell的值是从后台返回来的,求高手帮忙下

在下面代码中如何给每个每个cell添加title属性,cell的值是从后台返回来的,求高手帮忙下,第1张

import java.io.*import jxl.*… … … … try { //构建Workbook对象, 只读Workbook对象 //直接从本地文件创建Workbook //从输入流创建Workbook InputStream is = new FileInputStream(sourcefile)jxl.Workbook rwb = Workbook.getWorkbook(is)} catch (Exception e) { e.printStackTrace()} 一旦创建了Workbook,我们就可以通过它来访问Excel Sheet(术语:工作表)。参考下面的代码片段: //获取第一张Sheet表 Sheet rs = rwb.getSheet(0)我们既可能通过Sheet的名称来访问它,也可以通过下标来访问它。如果通过下标来访问的话,要注意的一点是下标从0开始,就像数组一样。 一旦得到了Sheet,我们就可以通过它来访问Excel Cell(术语:单元格)。参考下面的代码片段: //获取第一行,第一列的值 Cell c00 = rs.getCell(0, 0)String strc00 = c00.getContents()//获取第一行,第二列的值 Cell c10 = rs.getCell(1, 0)String strc10 = c10.getContents()//获取第二行,第二列的值 Cell c11 = rs.getCell(1, 1)String strc11 = c11.getContents()System.out.println("Cell(0, 0)" + " value : " + strc00 + "type : " + c00.getType())System.out.println("Cell(1, 0)" + " value : " + strc10 + "type : " + c10.getType())System.out.println("Cell(1, 1)" + " value : " + strc11 + "type : " + c11.getType())如果仅仅是取得Cell的值,我们可以方便地通过getContents()方法,它可以将任何类型的Cell值都作为一个字符串返回。示例代码中Cell(0, 0)是文本型,Cell(1, 0)是数字型,Cell(1,1)是日期型,通过getContents(),三种类型的返回值都是字符型。 如果有需要知道Cell内容的确切类型,API也提供了一系列的方法。参考下面的代码片段: String strc00 = nulldouble strc10 = 0.00Date strc11 = nullCell c00 = rs.getCell(0, 0)Cell c10 = rs.getCell(1, 0)Cell c11 = rs.getCell

两个insert方法返回的就是被插入的对象,直接 *** 作这两个对象就行了。

var tr = table.insertRow()var td = tr.insertCell()tr.setAttribute('align','center') '不用setAttribute而直接使用属性也可以.tr.setAttribute('bgcolor','#FF0000')

td.width=100  直接对属性赋值的作法。

要在tr元素的父元素中才能增加行,不能在tr本身去增加行。而tbody就是tr的父元素。如果是增加td,就要用tr,因为tr是td的父元素。

<script>// Last updated 2006-02-21 function addRowToTable() { var tbl = document.getElementById('tblSample')var lastRow = tbl.rows.length。

// if there's no header row in the table, then iteration = lastRow + 1

var iteration = lastRow。

var row = tbl.insertRow(lastRow)// left cell var cellLeft = row.insertCell(0)var textNode = document.createTextNode(iteration)cellLeft.appendChild(textNode)

// right cell var cellRight = row.insertCell。

var el = document.createElement('input')el.type = 'text'el.name = 'txtRow' + iterationel.id = 'txtRow' + iterationel.size = 40。

el.onkeypress = keyPressTestcellRight.appendChild(el)。

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="index.aspx.cs" Inherits="index" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>Cell(华表)</title>

<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312" />

<script type="text/javascript" language="javascript">

function cellReg() {

//华表注册

document.getElementById("cellweb1").Login("", "", "注册ID", "注册码")

}

</script>

<script language="javascript" type="text/javascript">

function onload() {

var cell = document.getElementById("cellweb1")

cell.ShowSideLabel(0, cell.GetCurSheet())//隐藏横向坐标

cell.ShowTopLabel(0, cell.GetCurSheet())//隐藏纵向坐标

}

</script>

<script language="javascript" type="text/javascript">

function getValue()

{

var date = new Date()

var startdate = date.getFullYear()+"-"+date.getMonth()+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds()

var enddate = date.getFullYear()+"-"+date.getMonth()+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds()

var printdate = date.getFullYear()+"-"+date.getMonth()+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds()

var err = document.all.cellweb1.openfile("<%=ConfigurationSettings.AppSettings["cell"].ToString()%>newCell.cll","")

if(err == -1)

{

alert("模板文件不存在请确认!")

}

var cell = document.getElementById("cellweb1")

for (var j = 0j <= 9j++)

{

cell.SetCellTextColor(1 + j, 3, cell.GetCurSheet(),1)

}

cell.SetCellInput(1, -1, cell.GetCurSheet(),5)//设置id列为只读

//填充模板头

cell.S(1,2,cell.GetCurSheet(),"开始时间:")

cell.S(2,2,cell.GetCurSheet(),startdate)

cell.S(3,2,cell.GetCurSheet(),"结束时间:")

cell.S(4,2,cell.GetCurSheet(),enddate)

cell.S(5,2,cell.GetCurSheet(),"打印时间:")

cell.S(7,2,cell.GetCurSheet(),printdate)

//填充模板头

//填充表头背景颜色

for(var h = 0h <= 9h++)

{

cell.SetCellBackColor(1+h,3,cell.GetCurSheet(), 5)

}

//填充表列名

cell.S(1,3,cell.GetCurSheet(),"序号")

cell.S(2,3,cell.GetCurSheet(),"编号")

cell.S(3,3,cell.GetCurSheet(),"传感器")

cell.S(4,3,cell.GetCurSheet(),"单位")

cell.S(5,3,cell.GetCurSheet(),"地点")

cell.S(6,3,cell.GetCurSheet(),"状态")

cell.S(7,3,cell.GetCurSheet(),"数值")

cell.S(8,3,cell.GetCurSheet(),"时间")

cell.S(9,3,cell.GetCurSheet(),"开始时间")

cell.S(10,3,cell.GetCurSheet(),"结束时间")

//填充表列名

var xh = document.getElementById("myxuhao").value //id

var nodeid = document.getElementById("mynodeid").value //nodeid

var sensor = document.getElementById("mysensor").value //传感器名

var unit = document.getElementById("myunit").value //单位

var placement= document.getElementById("myplacement").value//地点

var status= document.getElementById("mystatus").value //状态

var value= document.getElementById("myvalue").value//值

var save_time= document.getElementById("mysave_time").value//保存时间

var startTime= document.getElementById("mystartTime").value//开始时间

var endTime= document.getElementById("myendTime").value//结束时间

var str = new Array()

var str1 = new Array()

var str2 = new Array()

var str3 = new Array()

var str4 = new Array()

var str5 = new Array()

var str6 = new Array()

var str7 = new Array()

var str8 = new Array()

var str9 = new Array()

str = xh.split(",")

str1 = nodeid.split(",")

str2 = sensor.split(",")

str3 = unit.split(",")

str4 = placement.split(",")

str5 = status.split(",")

str6 = value.split(",")

str7 = save_time.split(",")

str8 = startTime.split(",")

str9 = endTime.split(",")

for(var i=0i<str.length++i)

{

cell.S(1,4+i,cell.GetCurSheet(), str[i])

cell.S(2,4+i,cell.GetCurSheet(), str1[i])

cell.S(3,4+i,cell.GetCurSheet(), str2[i])

cell.S(4,4+i,cell.GetCurSheet(), str3[i])

cell.S(5,4+i,cell.GetCurSheet(), str4[i])

cell.S(6,4+i,cell.GetCurSheet(), str5[i])

cell.S(7,4+i,cell.GetCurSheet(), str6[i])

cell.S(8,4+i,cell.GetCurSheet(), str7[i])

cell.S(9,4+i,cell.GetCurSheet(), str8[i])

cell.S(10,4+i,cell.GetCurSheet(), str9[i])

}

cell.ReDraw()//重新加载报表数据

}

</script>

<script type="text/javascript" language="javascript">

function btn_Edit()

{

//设置表页为只读

document.getElementById("cellweb1").WorkbookReadonly = false

//设置不支持允许拖动

document.getElementById("cellweb1").AllowDragdrop = false

}

//打印预览

function btn_PrePrint()

{

document.getElementById("cellweb1").PrintPreview(true, document.getElementById("cellweb1").GetCurSheet)

}

//打印

function btn_Print()

{

document.getElementById("cellweb1").PrintSheet(false, document.getElementById("cellweb1").GetCurSheet)

}

//保存

function btn_Save()

{

document.getElementById("cellweb1").SaveFile()

}

function btn_SetPrint()

{

document.getElementById("cellweb1").PrintPageSetup()

}

function fn_Print()

{

if (confirm("确定列印吗"))

{

document.all.btnWonem_tabButtonCtl.style.display = "none"

window.print()

return false

}

else

{

return false

}

}

</script>

<style type="text/css">

.style1

{

height: 526px

}

#btnquery

{

width: 66px

}

#btnedit

{

width: 68px

}

#btnprint

{

width: 73px

}

#btnsave

{

width: 75px

}

</style>

</head>

<!--onload="cellreg()"-->

<body onload="onload()">

<form id="form1" runat="server">

<table width="100%">

<tr>

<td height="50px">

<input id="btnquery" type="button" value="查询" onclick="return getValue()" />

<input id="btnedit" type="button" value="编辑" onclick="return btn_Edit()" />

<input id="btnpreprint" type="button" value="打印预览" onclick="return btn_PrePrint()" />

<input id="btnsetprint" type="button" value="打印设置" onclick="return btn_SetPrint()" />

<input id="btnprint" type="button" value="打印" onclick="return btn_Print()" />

<input id="btnsave" type="button" value="保存" onclick="return btn_Save()" />

<input type="hidden" name="myxuhao" id="myxuhao" value='<%=xuhao %>' />

<input type="hidden" name="mynodeid" id="mynodeid" value='<%=nodeid %>' />

<input type="hidden" name="mysensor" id="mysensor" value='<%=sensor %>' />

<input type="hidden" name="myunit" id="myunit" value='<%=unit %>' />

<input type="hidden" name="myplacement" id="myplacement" value='<%=placement %>' />

<input type="hidden" name="mystatus" id="mystatus" value='<%=status %>' />

<input type="hidden" name="myvalue" id="myvalue" value='<%=value %>' />

<input type="hidden" name="mysave_time" id="mysave_time" value='<%=save_time %>' />

<input type="hidden" name="mystartTime" id="mystartTime" value='<%=startTime %>' />

<input type="hidden" name="myendTime" id="myendTime" value='<%=endTime %>' />

</td>

</tr>

<tr>

<td class="style1">

<object id="cellweb1" style="z-index: 102left: 14pxwidth: 95%position: absolutetop: 70pxheight: 100%"

classid="clsid:3f166327-8030-4881-8bd2-ea25350e574a">

<param name="_version" value="65536" />

<param name="_extentx" value="14182" />

<param name="_extenty" value="7197" />

<param name="_stockprops" value="0" />

</object>

</td>

</tr>

</table>

</form>

</body>

</html>


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11562863.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-17
下一篇 2023-05-17

发表评论

登录后才能评论

评论列表(0条)

保存