import fonts.fontAwesome; import win.ui; /*DSG{{*/ var winform = win.form(text="aardio form";right=815;bottom=567) winform.add( btnWbPrint={cls="button";text="Print";left=752;top=448;right=792;bottom=472;z=9}; button={cls="button";text="Button";left=744;top=520;right=800;bottom=552;z=3}; button2={cls="button";text="Copy";left=736;top=104;right=784;bottom=128;z=4}; combobox={cls="combobox";left=736;top=168;right=808;bottom=192;edge=1;items={};mode="dropdownlist";z=8}; edit={cls="edit";left=16;top=16;right=728;bottom=280;db=0.51;dl=1;dr=0.11;dt=1;edge=1;font=LOGFONT(name='Consolas');hscroll=1;multiline=1;vscroll=1;z=1}; editOri={cls="edit";text="Edit";left=16;top=288;right=728;bottom=552;db=1;dl=1;dr=0.11;dt=0.51;edge=1;font=LOGFONT(name='Consolas');hscroll=1;multiline=1;vscroll=1;z=2}; plusCenter={cls="plus";left=760;top=64;right=780;bottom=84;bgcolor=-5197169;font=LOGFONT(h=-13);iconStyle={font=LOGFONT(h=-13;name='FontAwesome')};iconText='\uF037';textPadding={left=20};z=7}; plusLeft={cls="plus";left=736;top=64;right=756;bottom=84;bgcolor=-5197169;font=LOGFONT(h=-13);iconStyle={font=LOGFONT(h=-13;name='FontAwesome')};iconText='\uF036';notify=1;textPadding={left=20};z=5}; plusRight={cls="plus";left=784;top=64;right=804;bottom=84;bgcolor=-5197169;font=LOGFONT(h=-13);iconStyle={font=LOGFONT(h=-13;name='FontAwesome')};iconText='\uF038';textPadding={left=20};z=6} ) /*}}*/ /*** +完成每列等宽设计 +完成行内换行设计 ++完成换行后行内垂直居中设计 +完成对齐功能L、C、R +完成列合并功能 ++完成列合并后居中功能 +完成行合并功能 --待完成行合并后垂直居中功能 *修复列宽bug ***/ import console winform.editOri.text = /*** 阶段 逻辑信道 子帧类型 子帧简写 使用时隙类型 时隙简写 初始\r建网阶段 搜索逻辑信道 \- \- 初始搜索子帧 SearchSFrm 长搜索时隙 SRSlot \| 同\r步\r逻\r辑\r信\r道 自举子帧 BootSFrm 同步时隙 CS \| 自举应答子帧 RBootSFrm 同步时隙 CR 参数分发子帧 PSFrm 同步时隙 CP 入网周期帧阶段 同步逻辑信道 勤务同步子帧 SyncSFrm 同步时隙 S \| 业务逻辑信道 数据子帧 DataSFrm 基本数据时隙 D 信令逻辑信道 信令子帧 CSFrm 基本数据时隙 C ***/ /*** "\r"代表单元格内换行 "\-"代表与前列合并单元格,其后值忽略 "\|"代表与前行合并单元格 ***/ winform.combobox.items = {"空白字符";"制表符";"空格"} winform.combobox.selIndex =1 align = "" str2xls = function(str,ss,s,c){ if(!s){ s= "-" } if(!c){ c="+" } if(!ss){ ss=s } var strXls = ""; string.appendText = function(str){ strXls = strXls ++ str } var delta = 1; //默认两侧各多1个空格 var Rowstr = string.splitEx(str,'\r\n')//分行 var pattern = {"\s+";"\t+";" +"}; //截断规则 var Rowarr = table.map(Rowstr,lambda(v,k) string.splitEx(string.trimright(v),pattern[winform.combobox.selIndex]) )//分列 var Cmax = table.map(Rowarr,lambda(v,k) #v ); table.sort(Cmax)//获取最大列数Cmax[#Cmax] var Rmax={}//最大子行数 RowarrRN = table.map(Rowarr,function(v,k,result){//分子行 var a = {}; var rr = 1; //console.dump(v) for(i=1;Cmax[#Cmax];1){//#tmp[1]获取最大列而非#v是避免遗漏空列 var x = string.splitEx(v[i]==null?" ":v[i],"\\r"); //||代表元素换行 table.push(a,x) if(rr<#x){//当前行内排序,找出最大的子行数 rr=#x } } table.push(Rmax,rr) return a; }); //console.dump(RowarrRN) vc = function(arg,max){//数组元素居中 var arr = arg; var num = math.floor((max-#arr)/2); while(num){ table.insert(arr,"") num = num-1 } arr = table.slice(table.mix(arr,table.array(max,"")),1,max) return arr; } vc1line = function(arg){//行内(换行)垂直居中 var tmp = arg; for(i=1;#tmp;1){ for(j=1;#tmp[1];1){ tmp[i][j] = vc(tmp[i][j],Rmax[i]) } } return tmp; } var tmp = vc1line(RowarrRN) vc2line = function(i,j){//连续行(合并行)垂直居中 arr = vc(RowarrRN[i-1][j],Rmax[i-1]+2) return arr; } //console.dump(vc2line(3,3)) glA = function(str){//获取字符中ASCII字符个数 var llA = {}; string.search(llA,str,"\i" ) return #llA; } gw = function(){ //获取每列最大列宽 var wmax = {}; //每列最大列宽 for(j=1;#tmp[1];1){//col var llA = glA(tmp[1][j][1]) var w = string.len(tmp[1][j][1])-math.floor(llA/2)//;#tmp[1][j][1];#l1A}; //字符宽,字节宽,ASCII个数 for(i=1;#tmp;1){//row for(ii=1;Rmax[i];1){ if(tmp[i][j][ii]==null){ tmp[i][j][ii]= "" } var llA = glA(tmp[i][j][ii]) var l = string.len(tmp[i][j][ii])-math.floor(llA/2) if(w <= l){//字符最长 w = l//字符宽 } } } table.push(wmax,w) } return wmax; } var UserWmax = table.clone(gw()) //console.dump(UserWmax) txt2arrOri = function(){ var newstr = {}; for(i=1;#tmp;1){//row for(ii=1;Rmax[i];1){//元素换行 var rowsep={} var rowtxt={} for(j=1;#tmp[1];1){ // //新数组,[行号]={连接符; 单元格字符; sta;对应原txt所在行} var con = c; var dstr = string.repeat((UserWmax[j]+delta)*2,s) //var l = (UserWmax[j]-string.len(tmp[i][j][ii]))*2+math.round(glA(tmp[i][j][ii]))+2*delta; //需添加空格数 if(i == 2){//表头,last //dstr = string.repeat((UserWmax[j]+delta)*2,ss); } if(ii == 1){//子行不添加分割行 table.push(rowsep,{con;dstr;0}) } table.push(rowtxt,{"|";tmp[i][j][ii];0;i}) }//end j if(rowsep[1]!=null){ table.push(newstr,rowsep)//new row in cell; } table.push(newstr,rowtxt) //console.dump(newstr[i][2]) }//end ii }//end i return newstr; } //var txtArr = txt2arrOri() //console.dump(txt2arrOri()) formatarr = function(a){ var arg = a; gs = function(){ var a = table.array(#arg,#arg[1],0); for(i=1;#arg;1){//row for(j=1;#arg[1];1){ select(arg[i][j][2]) { case "\-" {//优先处理行内合并 a[i][j]=-1 if(j>1){ a[i][j-1]=-1 } } case "\|" { a[i][j]=1 } else { a[i][j]=0 } } } } return a; } var sta = gs() //console.dump(sta) //align aCell = function(str,w){//align current cell if(w==null){ //w=UserWmax[j] } var ll = (w-string.len(str))*2+math.round(glA(str))+2*delta; //需添加空格数 select(align) { case "Center" {//center return string.repeat(math.floor(ll/2)," ") ++ str ++ string.repeat(ll-math.floor(ll/2)," ")) } case "Right" {//right return string.repeat(ll-delta," ") ++ str ++ string.repeat(delta," ")) } else {//left return string.repeat(delta," ") ++ str ++ string.repeat(ll-delta," ")) } } } var tmpalign = align for(i=1;#arg;1){//row for(j=1;#arg[1];1){ if(arg[i][j][1] != c){//only txt if(i == 2){//表头强制居中 align = "Center" } else { align = tmpalign } arg[i][j][2] = aCell(arg[i][j][2],UserWmax[j]) } } } var Rc = Rowarr; var xd = txt2arrOri(); for(i=1;#arg;1){//row for(j=1;#arg[1];1){ if(arg[i][j][1] != c){//only txt //行合并 if(xd[i][j][2] == "\|" and i != 1 and sta[i-1] != -1){ //xd[i][j][2] = "" var k = 1; var r2c = Rmax[arg[i][j][4]] + Rmax[arg[i][j][4]-1]+1; var ori = {}; var r1 = i-math.floor((Rmax[arg[i][j][4]]-1)/2)-Rmax[arg[i][j][4]-1]-1 for(r=r1;r1+Rmax[arg[i][j][4]-1]-1;1){ table.push(ori,xd[r][j][2]) } //while(xd[i+2*(k)][j][2] == "\|"){ while(Rc[arg[i][j][4]+k][j] == "\|"){//txt下一行同列 //console.dump(k,Rmax[arg[i][j][4]+k]) Rc[arg[i][j][4]+k][j] = "" math.floor((Rmax[arg[i][j][4]]-1)/2) r2c += Rmax[arg[i][j][4]+k]+1 if(k!=#arg){ k += 1 } //console.dump(Rc) } ori = vc(ori,r2c) //console.dump(ori) for(r=1;#ori;1){ xd[r1+r-1][j][2]="" arg[r1+r-1][j][2]=aCell(ori[r],UserWmax[j]) } } //行内合并 if(xd[i][j][2] == "\-" and j != 1){//第一列无效 xd[i][j][2] = "" //check how many cells to compose var k = 1; var w = UserWmax[j]+UserWmax[j-1]; while(xd[i][j+k][2] == "\-"){ //console.log(k) xd[i][j+k][2] = "" w += UserWmax[j+k] if(k!=#arg[1]){ k += 1 } } //force align to center var r2c = Rmax[arg[i][j-1][4]]; for(r=i-math.floor((r2c-1)/2);i+r2c-math.floor((r2c-1)/2)-1;1){ var str = txt2arrOri()[r][j-1][2]; var ll = (w-string.len(str))*2+math.round(glA(str))+2*delta+(2*delta+1)*k; //需添加空格数 arg[r][j-1][2] = string.repeat(math.floor(ll/2)," ") ++ str ++ string.repeat(ll-math.floor(ll/2)," ") //arg[r][j][2] = "" for(n=0;k-1;1){ arg[r][j+n][2] = "" } } }//end } } } return arg; } arr2str = function(arr){ var strs = table.map(arr,function(v,k,result){ var c = v[1][1]; //var str = table.map(v,lambda(vv,kk) vv[2]) var str = {} for(i=1;#v;1){//去掉空cell,数组大小会减小,map不改变数组大小 if(v[i][2]!=""){ table.push(str,v[i][2]) } } return c++string.join(str,c)++c }) //console.dump(strs) strXls = string.join(strs,'\r\n') ++ '\r\n' ++ strs[1] } arr2str(formatarr(txt2arrOri())) return "
" ++ strXls ++"
"; }//end str2xls //write-space:pre|pre-line; import web.form var wb = web.form(winform.edit); wb.html = /** **/ winform.button2.oncommand = function(id,event){ wb.execWb( 0x11/*_OLECMDID_SELECTALL*/,0 ) wb.execWb( 0xC/*_OLECMDID_COPY*/,0 ) } winform.button.oncommand = function(id,event){ wb.body.innerHTML = str2xls(winform.editOri.text,"="); } for(name,ctrl in winform.eachControl("plus","plus*") ){ ctrl.skin({ background={ default=0x668FB2B0; disabled=0xFFCCCCCC; hover=0xFF928BB3 }; color={ default=0xFF000000; disabled=0xFF6D6D6D } }) ctrl.oncommand = function(id,event){ align = string.trimleft(name,"plus"); winform.button.oncommand() } } winform.button.oncommand() winform.editOri.onChange = function(){ winform.button.oncommand() } winform.combobox.oncommand= function(id,event){ var text = owner.selText; if(event == 9/*_CBN_SELENDOK*/){ winform.button.oncommand() } } //HTML格式打印 winform.btnWbPrint.oncommand = function(id,event){ wb.getDoc().execCommand("print") } winform.show(); win.loopMessage();