SOURCE

删除标记 = "是否导入";

//明细行的临时集合
var dtls = [];
//获取单元格最后一行
var sheet = dataOper.getSheetAt(0);
//获取工作表的最后一行
var maxRow = helper.getSheetLastRowNumber(sheet);

var cfg={
    列_柜体名称列:1,
    列_柜体规格列:2,
    列_板件名称列:3,
    列_板件宽度列:4,
}


//设定工作表的最后一行
function setMaxDataRow() {
    var realRow = maxRow;
    for (var i = maxRow; i > 0; i--) {
        var res = true;
        for (var j = 0; j < cfg.非空列判定是否数据行.length; j++) {
            var colindex = cfg.非空列判定是否数据行[j];
            var val = helper.getSheetVal(sheet, i, colindex);
            if (val == null || val == "") {
                res = false;
                break;
            }
        }
        if (res == true) {
            realRow = i;
            break;
        }
    }
    maxRow = realRow;
}



//公共函数
var fun = {
    //检查是否明细行
    checkIsDtlData: function (i) {
        try {
            var res = true;
            for (var j = 0; j < cfg.非空列判定是否明细行.length; j++) {
                var colindex = cfg.非空列判定是否明细行[j];
                var val = helper.getSheetVal(sheet, i, colindex);
                if (val == null || val == "") {
                    res = false;
                    break;
                }
            }
            return res;
        } catch (e) {
            throw "checkIsDtlData" + e;
        }
    },
    //检查是否子表行
    checkIsSubDtlData: function (i) {
        try {
            var res = true;
            for (var j = 0; j < cfg.非空列判定是否子表行.length; j++) {
                var colindex = cfg.非空列判定是否子表行[j];
                var val = helper.getSheetVal(sheet, i, colindex);
                if (val == null || val == "") {
                    res = false;
                    break;
                }
            }
            return res;
        } catch (e) {
            throw "checkIsSubDtlData" + e;
        }
    },
    //处理材质
    dealWithMatId: function (bean) {
    },
    checkIsDtl:function(i){
	   var name=
	},
    //根据行号获取新的明细行
    getNewDtl: function (i) {
        try {
            var dtl = {};
            dtl.prdId = -100;//导入表示
            dtl.prdName = helper.getSheetVal(sheet, i, );
            dtl.prdSpc = helper.getSheetVal(sheet, i, cfg.列_明细造型);
            dtl.rem = helper.getSheetVal(sheet, i, cfg.列_明细备注);
            dtl.wth = helper.getSheetVal(sheet, i, cfg.列_明细宽);
            dtl.hgt = helper.getSheetVal(sheet, i, cfg.列_明细高);
            dtl.thk = helper.getSheetVal(sheet, i, cfg.列_明细厚);
            dtl.qty_q = helper.getSheetVal(sheet, i, cfg.列_明细块);
            dtl.kw = helper.getSheetVal(sheet, i, cfg.列_明细开孔);

            //材质
            if (cfg.格_明细材质.行 == 0) {
                dtl.matName = helper.getSheetVal(sheet, i, cfg.格_明细材质.列);
                dtl.matId = fun.getMatInfo(dtl.matName).matId;
            } else {
                dtl.matName = helper.getSheetVal(sheet, cfg.格_明细材质.行,
                    cfg.格_明细材质.列);
                dtl.matId = fun.getMatInfo(dtl.matName).matId;
            }
            //颜色
            if (cfg.格_明细颜色.行 == 0) {
                dtl.clr = helper.getSheetVal(sheet, i, cfg.格_明细颜色.列);
            } else {
                dtl.clr = helper.getSheetVal(sheet, cfg.格_明细颜色.行,
                    cfg.格_明细颜色.列);
            }
            return dtl;
        } catch (e) {
            throw "getNewDtl出错" + e;
        }
    },
    //根据行号获取新的子表行
    getNewSubDtl: function (i) {
        var subDtl = {};

        subDtl.prdName = helper.getSheetVal(sheet, i, cfg.列_子表名称);
        var prdSpc = helper.getSheetVal(sheet, i, cfg.列_子表造型);
        var rem = helper.getSheetVal(sheet, i, cfg.列_子表备注);
        subDtl.rem = prdSpc + " " + rem;
        subDtl.wth = helper.getSheetVal(sheet, i, cfg.列_子表宽);
        subDtl.hgt = helper.getSheetVal(sheet, i, cfg.列_子表高);
        subDtl.thk = helper.getSheetVal(sheet, i, cfg.列_子表厚);
        subDtl.qty_q = helper.getSheetVal(sheet, i, cfg.列_子表块);
        subDtl.lock = true;
        //材质
        if (cfg.格_子表材质.行 == 0 && cfg.格_子表材质.列 > 0) {
            subDtl.matName = helper.getSheetVal(sheet, i, cfg.格_子表材质.列);
        } else if (cfg.格_子表材质.行 > 0 && cfg.格_子表材质.列 > 0) {
            subDtl.matName = helper.getSheetVal(sheet, cfg.格_明细材质.行,
                cfg.格_明细材质.列);
        }
        return subDtl;
    },
    dealWtihRow: function (i, lastdtl) {
        if (fun.checkIsDtlData(i)) {
            var dtl = fun.getNewDtl(i);
            dtl.prdType = 0;
            helper.setDtlBeanParam(dtl, 删除标记, "是");
            dtls.push(dtl);
            lastdtl = dtl;
        } else if (fun.checkIsSubDtlData(i)) {
            if (lastdtl == null) {
                throw "在处理行[" + i + "],系统判定为[二级料单],但其[产品项]未获取到"
            }
            var subDtl = fun.getNewSubDtl(i);
            if (lastdtl.dtls == null) {
                lastdtl.dtls = [];
            }
            //将子表行插入到上一个明细行中
            lastdtl.dtls.push(subDtl);
        }
        return lastdtl;
    },
    getMatInfo: function (matName) {
        var mat = helper.getMatInfo(matName);
        if (mat == null) {
            throw "材质[" + matName + "]在系统中不存在!";
        }
        return mat;
    }

}


//处理明细行
function dealWithRows() {
    var lastdtl = null;
    for (var i = cfg.行_数据起始行; i <= maxRow; i++) {
        try {
            lastdtl = fun.dealWtihRow(i, lastdtl);
        } catch (e) {
            throw "在处理第" + i + "行时错误," + e;
        }
    }
    //将临时的明细数组,插入到结果集

    for (var i = 0; i < dtls.length; i++) {
        @订单明细.push(dtls[i]);
    }

}
setMaxDataRow();
dealWithRows();



//处理表头行
function setMainInfo() {
    var cusName = helper.getSheetVal(sheet, cfg.格_客户名称.行, cfg.格_客户名称.列);
    var cusrName = helper.getSheetVal(sheet, cfg.格_终端客户.行, cfg.格_终端客户.列);
    var cusrPrd = helper.getSheetVal(sheet, cfg.格_空间区域.行, cfg.格_空间区域.列);
    var cusrRem = cusrName + " " + cusrPrd;
    var pNo = helper.getSheetVal(sheet, cfg.格_单号.行, cfg.格_单号.列);
    if(pNo==null || pNo==""){
	   throw "订单编号未填写!";
	}
    var matName = helper.getSheetVal(sheet, cfg.格_材质.行, cfg.格_材质.列);
    var clr = helper.getSheetVal(sheet, cfg.格_颜色.行, cfg.格_颜色.列);
    
    var cust = helper.getCustByOName(cusName);
    if (cust == null) {
        cust = helper.getCustByName(cusName);
        if (cust == null)
            throw "客户名称[" + cusName + "]在系统中不存在!";
    }
    var date = new Date();
    var year = String(date.getFullYear());
    year = year.substr(2, 2);
  


    订单主表.pNo = year + "-" + pNo;
    订单主表.cusId = cust.cusId;
    订单主表.cusName = cusName;
    订单主表.cusrName = cusrName;
    订单主表.cusrPrd = cusrPrd;
    订单主表.cusrRem = cusrRem;
    var mat = fun.getMatInfo(matName);
    订单主表.matId = mat.matId;
    订单主表.matName = matName;
    订单主表.clrName = clr;
    //交货期
    var needDay = helper.getSheetVal(sheet, 2, 6);
    needDay = needDay != null ? needDay.replace(/天/ig, "") : 0;
    订单主表.fkneedDay = needDay;
    //下单人
    订单主表.duName = helper.getSheetVal(sheet, 6, 4);
    //生产备注
    订单主表.rem = helper.getSheetVal(sheet, 7, 4);
}
setMainInfo();
console 命令行工具 X clear

                    
>
console