📄 spreadsheet.js
字号:
var dataXMLDOC ;
var optionsFlags ;
var optionsValues = new Array(); ////记录:表名|字段名|type|id|memo|extendtype|baseinfo
var iteminfoValues = new Array(); //纪录总的复合信息集的信息
var optionvalue="";
function divideOptionValue(optionvalue)
{
//optionvalue="epmsTirpTbl|vcCommon001ID|1|1|序列号|610001|0";
temp = optionvalue;
i = 0;
while(temp.indexOf("|")!=-1)
{
loc = temp.indexOf("|");
optionsValues[i] = temp.substring(0,loc);
i++;
temp = temp.substring(loc+1);
}
optionsValues[i] = temp ; //baseinfo
}
function deleteXmlNode(form,deledcell)
{
activecell = deledcell ;
for(i=0;i<dataXMLDOC.documentElement.childNodes.length;i++)
{
datanode = dataXMLDOC.documentElement.childNodes.item(i);
for(j=0;j<datanode.childNodes.length;j++)
{
fieldnode = datanode.childNodes.item(j); //每一个定义的结点
row = fieldnode.getAttribute("row");
col = fieldnode.getAttribute("col");
xx = activecell.row;
yy = activecell.column;
if(row==xx&&col==yy) //定义过并且符合 则删除
{
datanode.removeChild(fieldnode);
activecell.value="";
break ;
}
}
}
var innodelen=dataXMLDOC.documentElement.childNodes.length;
for(ip=0;ip<innodelen;ip++)
{
datanode = dataXMLDOC.documentElement.childNodes.item(ip);
if(!(datanode.childNodes.length>0))
{
dataXMLDOC.documentElement.removeChild(datanode);
break;
}
}
}
function ModifyStyle(form) //提交更改后的报表样式
{
form.action = "";
form.submit();
}
function OnLoadData(stylepath,datapath)
{
Spreadsheet.HTMLURL = stylepath.value ;
xmlDoc.load(datapath.value);
for(x=0;x<xmlDoc.documentElement.childNodes.length;x++)
{
currNode = xmlDoc.documentElement.childNodes.item(x);
row = currNode.getAttribute("row");
col = currNode.getAttribute("col");
value = currNode.getAttribute("value");
if(value.indexOf("0")==0)Spreadsheet.Cells(row,col).Value = "'"+value ;
else Spreadsheet.Cells(row,col).Value = value ;
}
}
function OnCountCond(form,infostr) //确定统计条件
{
//alert(infostr);
var allinfoarray=infostr.split("#||#");
var initeminfoarray=allinfoarray[2].split("^");
var conditionarray=allinfoarray[3].split("^");
var usersArray;
if(allinfoarray[0]=="0")
{
var rows = Spreadsheet.Selection.Rows.Count ;
var cols = Spreadsheet.Selection.Columns.Count ;
var beginrow = Spreadsheet.Selection.row;
var begincol = Spreadsheet.Selection.column;
var definedNode ;
var activecell = Spreadsheet.ActiveCell;
var datanode;
var seledtable;
defined = true;
var selectIndex=-1; //选中的option
var kkkk;
if(true)
{
nodecount=0;
data = allinfoarray[3];
optionsValues=data.split("&");
fieldname = optionsValues[1];//字段名称
activecell = Spreadsheet.ActiveCell ;//Excel对象的活动cell
for(i=0;i<dataXMLDOC.documentElement.childNodes.length;i++)
{
datanode = dataXMLDOC.documentElement.childNodes.item(i);
tablename = datanode.getAttribute("name"); //得到xml中的<table>元素的表名
if(optionsValues[1]==tablename)
{
seledtable=i;
break;
}
nodecount++;
}
//如果没有这个表的话,就在xml中创建这个表
if(nodecount==dataXMLDOC.documentElement.childNodes.length)
{
newDataNode = dataXMLDOC.createElement("table");
newDataNode.setAttribute("name",optionsValues[1]);
newDataNode.setAttribute("rep","0");
dataElement = dataXMLDOC.documentElement;
dataElement.appendChild(newDataNode);
newDataNode = dataXMLDOC.createElement("field");
i = activecell.row;
j = activecell.column;
newDataNode.setAttribute("row",i);
newDataNode.setAttribute("col",j);
newDataNode.setAttribute("name",optionsValues[2]);
newDataNode.setAttribute("showname",optionsValues[4]);
newDataNode.setAttribute("type",optionsValues[3]);
if(optionsValues[3]=="3")
{
newDataNode.setAttribute("format","yy-MM-dd");
}
if(optionsValues[5]!=""&&optionsValues[5]!=null)
{
newDataNode.setAttribute("code",optionsValues[5]);
}
if(optionsValues[6]!=""&&optionsValues[6]!=null)
{
newDataNode.setAttribute("consql",optionsValues[6]);
}
chfieldname = optionsValues[4];
}
else
{
newDataNode = datanode;
dataElement = dataXMLDOC.documentElement;
dataElement.appendChild(newDataNode);
newDataNode = dataXMLDOC.createElement("field");
i = activecell.row;
j = activecell.column;
newDataNode.setAttribute("row",i);
newDataNode.setAttribute("col",j);
newDataNode.setAttribute("name",optionsValues[2]);
newDataNode.setAttribute("showname",optionsValues[4]);
newDataNode.setAttribute("type",optionsValues[3]);
if(optionsValues[3]=="3")
{
newDataNode.setAttribute("format","yy-MM-dd");
}
if(optionsValues[5]!=""&&optionsValues[5]!=null)
{
newDataNode.setAttribute("code",optionsValues[5]);
}
if(optionsValues[6]!=""&&optionsValues[6]!=null)
{
newDataNode.setAttribute("consql",optionsValues[6]);
}
//newDataNode.setAttribute("rep","0");
chfieldname = optionsValues[4];
}
for(x=0;x<dataXMLDOC.documentElement.childNodes.length;x++)
{
datanode = dataXMLDOC.documentElement.childNodes.item(x);
for(i=0;i<datanode.childNodes.length;i++)
{
fieldnode = datanode.childNodes.item(i);
xxx = fieldnode.getAttribute("row");
yyy = fieldnode.getAttribute("col");
xxxx = activecell.row ;
yyyy = activecell.column ;
//alert("xxx:"+xxx+";yyy:"+yyy+";xxxx:"+xxxx+";yyyy:"+yyyy+";");
if(xxx==xxxx&&yyy==yyyy)
{
//alert("removeChild(fieldnode)");
//datanode.removeChild(fieldnode); //该格式中如果定义过则删除结点
deleteXmlNode(document.forms(0),Spreadsheet.Cells(xxxx,yyyy));
break ;
}
}
}
for(x=0;x<dataXMLDOC.documentElement.childNodes.length;x++)
{
datanode = dataXMLDOC.documentElement.childNodes.item(x);
datanode.appendChild(newDataNode);
}
if(chfieldname.indexOf(".")!=-1)activecell.value="["+chfieldname.substring(chfieldname.indexOf(".")+1)+"]";
else activecell.value = "["+chfieldname+"]";
//optionsFlags[selectIndex] = true ;//标记选择过
}
else //该字段已经定义过
{
kkkk = -1;
for(x=0;x<dataXMLDOC.documentElement.childNodes.length;x++)
{
datanode = dataXMLDOC.documentElement.childNodes.item(x);
for(i=0;i<datanode.childNodes.length;i++)
{
fieldnode = datanode.childNodes.item(i);
xxx = fieldnode.getAttribute("row");
yyy = fieldnode.getAttribute("col");
xxxx = activecell.row ;
yyyy = activecell.column ;
if(xxx==xxxx&&yyy==yyyy)
{
for(k=0;k<form.queryfield.options.length;k++)
{
datad = form.queryfield.options[k].value;
//divideOptionValue(datad);
optionsValues=datad.split("$");
fieldname1 = optionsValues[1];
if(fieldname1==fieldnode.nodeName) //找到对应的选择过的字段在select中的编号
{
kkkk = k ;
if(k!=selectIndex)
{
optionsFlags[k] = false ;//修改记录该字段是否被选择过的值
}
break ;
}
}
datad = form.queryfield.options[k].value;
//divideOptionValue(datad);
optionsValues=datad.split("$");
if(kkkk!=selectIndex)datanode.removeChild(fieldnode); //该格式中如果定义过则删除结点
break ;
}
}
}
data = form.queryfield.options[selectIndex].value;
//data = "epmsTirpTbl|vcCommon001ID|1|1|序列号|610001|0";
//表名|字段名|type|id|memo|extendtype|baseinfo
//divideOptionValue(data); //分隔
optionsValues=data.split("$");
fieldname = optionsValues[1];
for(x=0;x<dataXMLDOC.documentElement.childNodes.length;x++)
{
datanode = dataXMLDOC.documentElement.childNodes.item(x);
for(i=0;i<datanode.childNodes.length;i++)
{
fieldnode = datanode.childNodes.item(i);
if(fieldnode.nodeName==fieldname)
{
row = fieldnode.getAttribute("row");
col = fieldnode.getAttribute("col");
Spreadsheet.Activesheet.Cells(row,col).value = "";
row = activecell.row;col=activecell.column;
ssssT = form.queryfield.options[selectIndex].text ;
if(ssssT.indexOf(".")!=-1)ssssT = ssssT.substring(ssssT.indexOf(".")+1);
Spreadsheet.Activesheet.Cells(row,col).value = "["+ssssT+"]";
fieldnode.setAttribute("row",row);
fieldnode.setAttribute("col",col); //修改行列值
break;
}
}
}
}
}
else if((allinfoarray[0]=="1"))
{
//alert("iteminfoValues:"+allinfoarray[2]);
iteminfoValues=allinfoarray[2].split("^");
var rows = Spreadsheet.Selection.Rows.Count ;
var cols = Spreadsheet.Selection.Columns.Count ;
var beginrow = Spreadsheet.Selection.row;
var begincol = Spreadsheet.Selection.column;
var definedNode ;
var activecell = Spreadsheet.ActiveCell;
var datanode;
var seledtable;
defined = true;
var selectIndex=-1; //选中的option
var kkkk;
//alert("iteminfoValues.length-1:"+(iteminfoValues.length-1));
for(tt=0;tt<iteminfoValues.length-1;tt++)
{
//alert("tt:"+tt);
if(true)
{
nodecount=0;
data = iteminfoValues[tt];
optionsValues=data.split("&,&");
fieldname = optionsValues[1];
activecell = Spreadsheet.ActiveCell ;
for(i=0;i<dataXMLDOC.documentElement.childNodes.length;i++)
{
datanode = dataXMLDOC.documentElement.childNodes.item(i);
tablename = datanode.getAttribute("name");
if(optionsValues[1]==tablename&&allinfoarray[4]==datanode.getAttribute("timemark"))
{
seledtable=i;
break;
}
nodecount++;
}
var rowrow;
var colcol;
if(nodecount==dataXMLDOC.documentElement.childNodes.length)
{
newDataNode = dataXMLDOC.createElement("table");
newDataNode.setAttribute("name",optionsValues[1]);
newDataNode.setAttribute("rep","1");
newDataNode.setAttribute("timemark",allinfoarray[4]);
dataElement = dataXMLDOC.documentElement;
dataElement.appendChild(newDataNode);
newDataNode = dataXMLDOC.createElement("field");
i = activecell.row;
j = activecell.column;
newDataNode.setAttribute("row",i);
newDataNode.setAttribute("col",j);
newDataNode.setAttribute("condition","");
//newDataNode.setAttribute("actcount","0");
newDataNode.setAttribute("name",optionsValues[2]);
newDataNode.setAttribute("showname",optionsValues[4]);
newDataNode.setAttribute("type",optionsValues[3]);
if(optionsValues[3]=="3")
{
newDataNode.setAttribute("format","yy-MM-dd");
}
if(optionsValues[5]!=""&&optionsValues[5]!=null)
{
newDataNode.setAttribute("code",optionsValues[5]);
}
if(optionsValues[6]!=""&&optionsValues[6]!=null)
{
newDataNode.setAttribute("consql",optionsValues[6]);
}
chfieldname = optionsValues[4];
rowrow=i;
colcol=j;
}
else
{
newDataNode = datanode;
dataElement = dataXMLDOC.documentElement;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -