本地表导入多维表
wils
Lv.4 核心创作者
昨天有朋友问,如何用本地表数据,批量更新多维表里的某个字段
https://bbs.wps.cn/topic/91940
如果用灵犀claw,直接对话就可以了
但若经常需要进行类似操作,弄个宏,每次点一下按钮也不错
多维表里的airscript这样:
const d = Context.argv.data
const r = Application.Sheets("导入数据").RecordRange
for (let i = 1; i <= r.Count; i++) {
if (r(i, "@文本").Value in d) {
r(i, "@数字").Value = d[r(i, "@文本").Value]
}
}多维表名称是"导入数据",列名分别是"文本"和"数字",根据需要修改
本地表里的js宏这样:
function tt()
{
const d = {}
for (const i of Sheets(1).UsedRange.Value2) {
d[i[0]] = i[1]
}
fetch("XXX", {
method: "POST",
headers: {
"Content-Type": "application/json",
"AirScript-Token": "YYY"
},
body: JSON.stringify({"Context":{"argv":{"data":d}}})
}).then(r => r.json()).then(j => {
console.log(j.status)
})
}这里的XXX和YYY需要改成你的webhook地址和脚本令牌
大概意思是将Sheet1转为字典d,传递给webhook
并不完善,比如若有多维表里不存在的行,是否新建等,根据需要再修改
