Skip to content

Instantly share code, notes, and snippets.

@cpuwolf
Last active January 12, 2024 07:37
Show Gist options
  • Save cpuwolf/5fdef70bb43ef25d631aa12ba70454ce to your computer and use it in GitHub Desktop.
Save cpuwolf/5fdef70bb43ef25d631aa12ba70454ce to your computer and use it in GitHub Desktop.
金山数据表Airscript数据处理
//
// Get a date object for the current time
var d = new Date();
// Set it to one month ago
d.setMonth(d.getMonth() - 1);
d.setDate(1)
// Zero the time component
d.setHours(0, 0, 0, 0);
// Get the time value in milliseconds and convert to seconds
datestr = d.toLocaleDateString("zh-CN")
console.log(datestr);
// 获取当前工作表
const currentSheet = ActiveSheet
console.log(Application.ActiveSheet.Name)
Application.Sheets.Item('国外订单自动化').Activate()
const sheet = Application.ActiveSheet
function fetchAllRecords() {
const view = sheet.Selection.GetActiveView()
let all = []
let offset = null;
while (all.length === 0 || offset) {
let records = sheet.Record.GetRecords({
ViewId: view.viewId,
Offset: offset,
MaxRecords: 10,
Fields: ["编号","状态", "日期","快递信息"],
Filter: {"mode": "AND", "criteria": [{
"field": "状态",
"op": "intersected",
"values": ["生产中"]
},{
"field": "日期",
"op": "Greater",
"values": [datestr]
},]}
})
offset = records.offset
all = all.concat(records.records);
}
console.log(all.length);
return all
}
const recs = fetchAllRecords();
console.log(recs)
for(var i=0; i< recs.length; i++) {
const shipinfo = recs[i].fields["快递信息"];
var bupd = false;
var txtlist;
if(shipinfo.startsWith("#")){continue;}
const txtlist4=shipinfo.split(' ');
const txtlist3=shipinfo.split(' ');
const txtlist0=shipinfo.split('\n');
console.log(txtlist4);
console.log(txtlist3);
console.log(txtlist0);
if(txtlist4.length == 3) {bupd = true;txtlist = txtlist4;}
else if(txtlist3.length == 3) {bupd = true;txtlist = txtlist3;}
else if(txtlist0.length == 3) {bupd = true;txtlist = txtlist0;}
if(bupd) {
//insert first
txtlist.unshift("#"+recs[i].fields["编号"]);
const multlinetxt = txtlist.join('\n');
console.log(multlinetxt);
const upded = sheet.Record.UpdateRecords({
Records: [{
id: recs[i].id,
fields: {
"快递信息": multlinetxt,
}
}],
})
console.log(upded);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment