代码拉取完成,页面将自动刷新
import win.ui;
import com.excel;
import fsys.dlg;
import win.ui.ctrl.vlistEx;
import console;
/*DSG{{*/
mainForm = win.form(text="xlsToDdl";right=1280;bottom=800)
mainForm.add(
edit={cls="edit";text="Excel 内容";left=30;top=750;right=1007;bottom=790;edge=1;multiline=1;z=4};
groupbox={cls="groupbox";text="预览";left=20;top=20;right=1016;bottom=800;cp=1;db=1;dl=1;dr=1;dt=1;edge=1;group=1;z=1};
listview={cls="listview";left=29;top=40;right=1007;bottom=746;edge=1;z=5};
loadXls={cls="button";text="打开工单表";left=1020;top=24;right=1190;bottom=64;bgcolor=11838087;z=2};
saveDdl={cls="button";text="保存标签文件";left=1020;top=80;right=1190;bottom=120;z=3}
)
/*}}*/
import win.ui.grid;
var grid = win.ui.grid(mainForm.listview);
//tm = time("%Y%m%d");
//console.log(tm);
mainForm.loadXls.oncommand = function(id,event){
var fileName = fsys.dlg.open("*.xls",,,winform);
//var fileName = "147--.xls";
if(fileName) {
mainForm.groupbox.text = fileName;
var editText = "";
var list = excelData(fileName); // 实际数据,从excel 文件读取
/*测试用数据{{*/
var list = {
Items={
[1]={wantDate=time(1634718179,"%Y-%m-%d");itemID="001";memo="";startDate=time(1634718179,"%Y-%m-%d");qty=71;PartID="TX-MM2LULULULU20005";des="跳线-LC/UPC+LC/UPC-LC/UPC+LC/UPC -5M 2.0双芯多模"};
[2]={wantDate=time(1634718179,"%Y-%m-%d");itemID="002";memo="";startDate=time(1634718179,"%Y-%m-%d");qty=134;PartID="TX-MM2LULULULU20008";des="跳线-LC/UPC+LC/UPC-LC/UPC+LC/UPC-2.0-8M 多模双芯"};
[3]={wantDate=time(1634718180,"%Y-%m-%d");itemID="003";memo="";startDate=time(1634718180,"%Y-%m-%d");qty=79;PartID="TX-MM2LULULULU20009";des="跳线-LC/UPC+LC/UPC-LC/UPC+LC/UPC-9M 2.0 双芯多模"};
[4]={wantDate=time(1634718180,"%Y-%m-%d");itemID="004";memo="";startDate=time(1634718180,"%Y-%m-%d");qty=60;PartID="TX-MM2LULULULU20010";des="跳线-LC/UPC+LC/UPC-LC/UPC+LC/UPC -10M 2.0多模双芯"};
[5]={wantDate=time(1634718180,"%Y-%m-%d");itemID="005";memo="";startDate=time(1634718180,"%Y-%m-%d");qty=5;PartID="TX-MM2LULULULU20013";des="跳线-LC/UPC+LC/UPC-LC/UPC+LC/UPC-13M 2.0 双芯多模"};
[6]={wantDate=time(1634718180,"%Y-%m-%d");itemID="006";memo="";startDate=time(1634718180,"%Y-%m-%d");qty=5;PartID="TX-MM2LULULULU20014";des="跳线-LC/UPC+LC/UPC-LC/UPC+LC/UPC-14M 2.0双芯多模"};
[7]={wantDate=time(1634718180,"%Y-%m-%d");itemID="007";memo="";startDate=time(1634718180,"%Y-%m-%d");qty=4;PartID="TX-MM2LULULULU20015";des="跳线-LC/UPC+LC/UPC-LC/UPC+LC/UPC-15M 2.0 双芯多模"};
[8]={wantDate=time(1634718180,"%Y-%m-%d");itemID="008";memo="";startDate=time(1634718180,"%Y-%m-%d");qty=8;PartID="TX-MM2LULULULU20016";des="跳线-LC/UPC+LC/UPC-LC/UPC+LC/UPC-16M 2.0 双芯多模"};
[9]={wantDate=time(1634718180,"%Y-%m-%d");itemID="009";memo="";startDate=time(1634718180,"%Y-%m-%d");qty=6;PartID="TX-MM2LULULULU20017";des="跳线-LC/UPC+LCUPC-LC/UPC+LC/UPC-2.0-17M 多模双芯"};
[10]={wantDate=time(1634718181,"%Y-%m-%d");itemID="010";memo="";startDate=time(1634718180,"%Y-%m-%d");qty=3;PartID="TX-MM2LULULULU20018";des="跳线-LC/UPC+LC/UPC-LC/UPC+LC/UPC-2.0-18M 多模双芯"};
[11]={wantDate=time(1634718183,"%Y-%m-%d");itemID="011";memo="";startDate=time(1634718183,"%Y-%m-%d");qty=2;PartID="TX-MM2LULULULU20019";des="跳线-LC/UPC+LC/UPC-LC/UPC+LC/UPC-19M 2.0 双芯多模"};
[12]={wantDate=time(1634718184,"%Y-%m-%d");itemID="012";memo="";startDate=time(1634718184,"%Y-%m-%d");qty=2;PartID="TX-MM2LULULULU20020";des="跳线-2LC/UPC-2LC/UPC-20M 2.0 双芯多模"};
[13]={wantDate=time(1634718184,"%Y-%m-%d");itemID="013";memo="";startDate=time(1634718184,"%Y-%m-%d");qty=1;PartID="TX-MM2LULULULU20021";des="跳线-LC/UPC+LC/UPC-LC/UPC+LC/UPC-21M 2.0 双芯多模"};
[14]={wantDate=time(1634718184,"%Y-%m-%d");itemID="014";memo="";startDate=time(1634718184,"%Y-%m-%d");qty=20;PartID="TX-MM2LULULULU20028";des="跳线-LC/UPC+LC/UPC-LC/UPC+LC/UPC-28M 2.0 双芯多模"}
fields={[1]="itemID", [2]="PartID", [3]="des", [4]="qty", [5]="startDate", [6]="wantDate", [7]="memo"};
widths={[1]=30, [2]=171, [3]=472, [4]=30, [5]=80, [6]=80, [7]=200};
};
MaxLens={wantDate=10;itemID=3;des=59;startDate=10;qty=3;PartID=19;memo=0};
WorkSheetId='\u2116:W210147'
};
//Title={"项号"; "物料编号"; "型号"; "数量"; "下单日期"; "交期"; "备注";};
//widths={[1]=30, [2]=171, [3]=472, [4]=30, [5]=80, [6]=80, [7]=200};
/*}}*/
gridList(list);
//mainForm.edit.text = display(list);
};
}
excelData = function(xlsName){/*这里是读取excel文件{{*/
import console;
//var tm = time("2000-1-1","%Y-%m-%d");
//console.log(tm);
var xls = com.excel();
var workBook = xls.Open(xlsName);
var sheet = workBook.ActiveSheet();
var cols = sheet.UsedRange.Columns.count;
var rows = sheet.UsedRange.Rows.count;
//console.log("Cols:", cols, '\tRows:', rows);
var list = {};
var items = {};
for(i=7;rows-3;1){
var item = {
itemID = sheet.Cells(i, 1).getValue2();
PartID = sheet.Cells(i, 2).getValue2();
des = sheet.Cells(i, 3).getValue2();
qty = sheet.Cells(i, 6).getValue2();
startDate = time("2000-1-1","%Y-%m-%d").addday(sheet.Cells(i, 7).getValue2() - 36524);
wantDate = time("2000-1-1","%Y-%m-%d").addday(sheet.Cells(i, 8).getValue2() - 36524);
memo = sheet.Cells(i, 9).getValue2();
};
//console.log(item.startDate, '\t', item.wantDate);
table.push(items, item);
//console.log(type(sheet.Cells(7, 2).getValue2()), sheet.Cells(7, 2).getValue2())
}
items["fields"] = {[1]="itemID", [2]="PartID", [3]="des", [4]="qty", [5]="startDate", [6]="wantDate", [7]="memo"};
// 获取工单项中每列的最大长度
var maxLens = {};
for(k,v in items){
for(k,v in v){
//console.log(k,v)
if(!maxLens[k] or maxLens[k] < #tostring(v)){
maxLens[k] = #tostring(v)
}
}
}
list["widths"] = {
[1] = maxLens["itemID"] * 15;
[2] = maxLens["PartID"] * 10;
[3] = maxLens["des"] * 10;
[4] = maxLens["qty"] * 15;
[5] = maxLens["startDate"] * 10;
[6] = maxLens["wantDate"] * 10;
[7] = maxLens["memo"] * 10;
}
list["Items"] = items;
list["WorkSheetId"] = sheet.Cells(3, 8).getValue2();
list["Title"] = {
[1] = "项号";
[2] = "物料编号";
[3] = "型号";
[4] = "数量";
[5] = "下单日期";
[6] = "交期";
[7] = "备注";
}
list["ReadOnly"] = { [1] = true };//设置禁止编辑的列 grid.readonlyColums =
//console.dump(list);
return list;
/*}}*/
}
gridList = function(list){/*使用listView显示表中的数据{{*/
//console.dump(list);
grid.setColumns(list["Title"], list["widths"]);
grid.setTable(list["Items"]);
/*}}*/
}
space = function(item, col, maxlens){/*按照最大内容长度添加空管{{*/
var description = "";
for(i=1;7;1){
var t = col[i]; // 对应显示内容的列宽
var realLength = tonumber(maxlens[t]) / 8;
//console.log((realLength));
var displayLength = math.floor(realLength) + 1;
//var str = type(item[t]) == string ? item[t]: ;
description = description ++ tostring(item[t]);
//console.dump(i, '\t', item[t]);
var tabNum = displayLength - math.floor(#tostring(item[t]) / 8)
for(i=0;tabNum;1){
description += '\t';
}
}
description += '\r\n';
return description;
/*}}*/
}
tableConsole = function(tbl){/*输出表内容{{*/
console.log("This is console of the Table:", tostring(tbl))
for(k, v in tbl){
console.log(k,v)
}
/*}}*/
}
mainForm.saveDdl.oncommand = function(id,event){/*生成打印文件DDL{{*/
var ddl = io.open("b.ddl","w+");
//fsys.file(
ddl.write("5200000fdfddsss");
var txt = tostring(ddl.read(2));
console.log(txt);
ddl.close();
/*}}*/
}
mainForm.show();
return win.loopMessage();
// 下面的display函数不用了
display = function(list){/*excel文件转存到显示字符串{{*/
var maxlens = list["MaxLens"];
var title = list["Title"];
var items = list["Items"];
var description = '工单号:\t' ++ list["WorkSheetId"];
description += '\r\n\r\n';
var col = {"itemID", "PartID", "des", "qty", "startDate", "wantDate", "memo"};
description += space(title, col, maxlens);
for(i=1;#items;1){
var item = items[i];
console.dump(item);
description += space(item, col, maxlens);
}
/*}}*/
return description;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。