了解正则表达式分组的应用(做报表字段名过多怎么办?)
字段名
orderNo
batchNo
model
catacity
unit
planQty
opName
planFinishDate
finishDate
planFinishQty
finishQty
finishProgerss
orderStatus
overdueType
batchOpOverdueExplain
notpad++查找与替换填写
^(w*)$
var 1 = document.createElement('td'); 1.innerHTML = records[i].1!=null&&records[i].1!=undefined?records[i].1:""; tr.appendChild(1);
替换结果
var orderNo = document.createElement('td');
orderNo.innerHTML = records[i].orderNo!=null&&records[i].orderNo!=undefined?records[i].orderNo:"";
tr.appendChild(orderNo);
var batchNo = document.createElement('td');
batchNo.innerHTML = records[i].batchNo!=null&&records[i].batchNo!=undefined?records[i].batchNo:"";
tr.appendChild(batchNo);
var model = document.createElement('td');
model.innerHTML = records[i].model!=null&&records[i].model!=undefined?records[i].model:"";
tr.appendChild(model);
var catacity = document.createElement('td');
catacity.innerHTML = records[i].catacity!=null&&records[i].catacity!=undefined?records[i].catacity:"";
tr.appendChild(catacity);
var unit = document.createElement('td');
unit.innerHTML = records[i].unit!=null&&records[i].unit!=undefined?records[i].unit:"";
tr.appendChild(unit);
var planQty = document.createElement('td');
planQty.innerHTML = records[i].planQty!=null&&records[i].planQty!=undefined?records[i].planQty:"";
tr.appendChild(planQty);
var opName = document.createElement('td');
opName.innerHTML = records[i].opName!=null&&records[i].opName!=undefined?records[i].opName:"";
tr.appendChild(opName);
var planFinishDate = document.createElement('td');
planFinishDate.innerHTML = records[i].planFinishDate!=null&&records[i].planFinishDate!=undefined?records[i].planFinishDate:"";
tr.appendChild(planFinishDate);
var finishDate = document.createElement('td');
finishDate.innerHTML = records[i].finishDate!=null&&records[i].finishDate!=undefined?records[i].finishDate:"";
tr.appendChild(finishDate);
var planFinishQty = document.createElement('td');
planFinishQty.innerHTML = records[i].planFinishQty!=null&&records[i].planFinishQty!=undefined?records[i].planFinishQty:"";
tr.appendChild(planFinishQty);
var finishQty = document.createElement('td');
finishQty.innerHTML = records[i].finishQty!=null&&records[i].finishQty!=undefined?records[i].finishQty:"";
tr.appendChild(finishQty);
var finishProgerss = document.createElement('td');
finishProgerss.innerHTML = records[i].finishProgerss!=null&&records[i].finishProgerss!=undefined?records[i].finishProgerss:"";
tr.appendChild(finishProgerss);
var orderStatus = document.createElement('td');
orderStatus.innerHTML = records[i].orderStatus!=null&&records[i].orderStatus!=undefined?records[i].orderStatus:"";
tr.appendChild(orderStatus);
var overdueType = document.createElement('td');
overdueType.innerHTML = records[i].overdueType!=null&&records[i].overdueType!=undefined?records[i].overdueType:"";
tr.appendChild(overdueType);
var batchOpOverdueExplain = document.createElement('td');
batchOpOverdueExplain.innerHTML = records[i].batchOpOverdueExplain!=null&&records[i].batchOpOverdueExplain!=undefined?records[i].batchOpOverdueExplain:"";
tr.appendChild(batchOpOverdueExplain);
也可分步进行
分步正则
var 1 = document.createElement('td');
1.innerHTML = records[i].1!=null&&records[i].1!=undefined?records[i].1:"";
tr.appendChild(1);
分步结果
var orderNo = document.createElement('td');
var batchNo = document.createElement('td');
var model = document.createElement('td');
var catacity = document.createElement('td');
var unit = document.createElement('td');
var planQty = document.createElement('td');
var opName = document.createElement('td');
var planFinishDate = document.createElement('td');
var finishDate = document.createElement('td');
var planFinishQty = document.createElement('td');
var finishQty = document.createElement('td');
var finishProgerss = document.createElement('td');
var orderStatus = document.createElement('td');
var overdueType = document.createElement('td');
var batchOpOverdueExplain = document.createElement('td');
orderNo.innerHTML = records[i].orderNo!=null&&records[i].orderNo!=undefined?records[i].orderNo:"";
batchNo.innerHTML = records[i].batchNo!=null&&records[i].batchNo!=undefined?records[i].batchNo:"";
model.innerHTML = records[i].model!=null&&records[i].model!=undefined?records[i].model:"";
catacity.innerHTML = records[i].catacity!=null&&records[i].catacity!=undefined?records[i].catacity:"";
unit.innerHTML = records[i].unit!=null&&records[i].unit!=undefined?records[i].unit:"";
planQty.innerHTML = records[i].planQty!=null&&records[i].planQty!=undefined?records[i].planQty:"";
opName.innerHTML = records[i].opName!=null&&records[i].opName!=undefined?records[i].opName:"";
planFinishDate.innerHTML = records[i].planFinishDate!=null&&records[i].planFinishDate!=undefined?records[i].planFinishDate:"";
finishDate.innerHTML = records[i].finishDate!=null&&records[i].finishDate!=undefined?records[i].finishDate:"";
planFinishQty.innerHTML = records[i].planFinishQty!=null&&records[i].planFinishQty!=undefined?records[i].planFinishQty:"";
finishQty.innerHTML = records[i].finishQty!=null&&records[i].finishQty!=undefined?records[i].finishQty:"";
finishProgerss.innerHTML = records[i].finishProgerss!=null&&records[i].finishProgerss!=undefined?records[i].finishProgerss:"";
orderStatus.innerHTML = records[i].orderStatus!=null&&records[i].orderStatus!=undefined?records[i].orderStatus:"";
overdueType.innerHTML = records[i].overdueType!=null&&records[i].overdueType!=undefined?records[i].overdueType:"";
batchOpOverdueExplain.innerHTML = records[i].batchOpOverdueExplain!=null&&records[i].batchOpOverdueExplain!=undefined?records[i].batchOpOverdueExplain:"";
tr.appendChild(orderNo);
tr.appendChild(batchNo);
tr.appendChild(model);
tr.appendChild(catacity);
tr.appendChild(unit);
tr.appendChild(planQty);
tr.appendChild(opName);
tr.appendChild(planFinishDate);
tr.appendChild(finishDate);
tr.appendChild(planFinishQty);
tr.appendChild(finishQty);
tr.appendChild(finishProgerss);
tr.appendChild(orderStatus);
tr.appendChild(overdueType);
tr.appendChild(batchOpOverdueExplain);