自动生成模板附件的脚本,生成附件感觉写得有点复杂,有没有高手给改一下
//获取记录ID
const record = Context.argv.record
//const sheet = Context.argv.sheet
//Application.Sheets("生产汇总").RecordRange(1,"@文本").Value = `'${record}'`
//let shengchandanhao = Application.Sheets("生产汇总").RecordRange(record,'@生产单号').Value
//console.log(shengchandanhao)
//生产单号作为附件名称先赋值
let shengchandanhao = Application.Sheets("生产汇总").RecordRange(record,'@生产单号').Value
//复制模板并打开
let url = KSDrive.createFile(KSDrive.FileType.ET,{
name: shengchandanhao+'.xlsx',
source: 模板URL
dirUrl: 附件保存地址
})
let file = KSDrive.openFile(url).Application
//文本字符段赋值函数
function yingshe(x,y){
file.Range(`${x}`).Value = Application.Sheets("生产汇总").RecordRange(record,`${y}`).Value
}
//用函数赋值给模板
yingshe('B3','@生产单号')
yingshe()
//其他类型字符段赋值
let kehu = Application.Sheets("生产汇总").RecordRange(record,"@客户").Value._core[0].str
//取URL地址的最后一段给属性赋值
const kk = url.replace(/\/+$/,'').split('/');
const yy = kk.pop()
console.log(yy)
const records = Application.Record.UpdateRecords
({
SheetId: 1,
Records:
[{
id: `${record}`,
fields:
{
图片和附件:[{
"fileName":shengchandanhao+'.xlsx',
"linkUrl": url,
"size":100,
"source":"cloud",
"type":"xlsx",
"uploadId":yy}]
}
}]
}
)
file.save
file.close
