这些是我正在运行的示例代码
“script_url”是部署并生成的google脚本web应用程序
sample.py
import requests
import datetime
url = "script_url?client_name={}&client_address={}&company_name={}&company_address={}&vessel_name={}&po={}&id={}&date={}&item1={}&item2={}&item3={}&cost1={}&cost2={}&cost3={}&total={}"
name_client = ["inder", "sawpnesh", "kajal"]
address_client = ["addInder", "addswapnesh", "addkajal"]
name_company = ["ospl", "ospl", "ospl"]
address_company = ["addospl", "addospl", "addospl"]
vessel_name = ["redlips", "elizabth", "jack"]
po = ["EWDCC", "wefwec", "asxwq"]
invoice_ids = ["1", "2", "3"]
item1 = ["keyboard", "mouse", "screen"]
item2 = ["mouse", "screen", "keyboard"]
item3 = ["screen", "keyboard", "mouse"]
cost1 = ["1000", "500", "2000"]
cost2 = ["500", "2000", "1000"]
cost3 = ["2000", "1000", "500"]
i = 0
for invoice_id in invoice_ids:
total = cost3[i] + cost2[i] + cost1[i]
print("processing ", invoice_id)
response = requests.get(
url.format(name_client[i], address_client[i], name_company[i], address_company[i], vessel_name[i], po[i],
invoice_id, datetime.date.today(), item1[i], item2[i], item3[i], cost1[i],
cost2[i], cost3[i], total
))
# response = requests.get(
# url.format(invoice_id, cust_names[i], add_streets[i], add_citys[i], issue_dates[i], last_dates[i]))
print("file generated")
response = requests.get(response.content)
print("file downloaded")
i += 1
with open("invoice{}.pdf".format(invoice_id), "wb") as f:
f.write(response.content)
# i += 1
这是我正在运行的谷歌脚本应用程序 代码.cs
function createDocument(id,client_name,client_address,company_name,company_address,vessel_name,po,date,item1,item2,item3,cost1,cost2,cost3,total) {
var TEMPLATE_ID = 'template_id';
var documentId = DriveApp.getFileById(TEMPLATE_ID).makeCopy().getId();
drivedoc = DriveApp.getFileById(documentId);
drivedoc.setName("Invoice " + id+"/2021");
doc = DocumentApp.openById(documentId);
var body = doc.getBody();
body.replaceText('{id}', id);
body.replaceText('{client_name}',client_name);
body.replaceText('{client_address}',client_address);
body.replaceText('{company_name}',company_name);
body.replaceText('{company_address}',company_address);
body.replaceText('{vessel_name}',vessel_name);
body.replaceText('{po}',po);
body.replaceText('{date}',date);
body.replaceText('{item1}',item1);
body.replaceText('{item2}',item2);
body.replaceText('{item3}',item3);
body.replaceText('{cost1}',cost1);
body.replaceText('{cost2}',cost2);
body.replaceText('{cost3}',cost3);
body.replaceText('{total}',total);
drivedoc.setSharing(DriveApp.Access.ANYONE_WITH_LINK, DriveApp.Permission.EDIT);
return "https://docs.google.com/document/d/" + documentId + "/export?format=pdf";
}
function doGet(e) {
var id = e.parameter.id;
var client_name = e.parameter.client_name;
var client_address = e.parameter.client_address;
var company_address = e.parameter.company_address;
var company_name = e.parameter.company_name;
var vessel_name = e.parameter.vessel_name;
var po = e.parameter.po;
var date = e.parameter.date;
var item1 = e.parameter.item1;
var item2 = e.parameter.item2;
var item3 = e.parameter.item3;
var cost1 = e.parameter.cost1;
var cost2 = e.parameter.cost2;
var cost3 = e.parameter.cost3;
var total = e.parameter.total;
var url = createDocument(id,client_name,client_address,company_name,company_address,vessel_name,po,date,item1,item2,item3,cost1,cost2,cost3,total);
return ContentService.createTextOutput(url);
}
当我执行url时
script_url?client_name=inder&client_address=addinder&company_name=ospl&company_address=ospladd&vessel_name=SEAQUEEN&po=324231&id=1&date=12/1/21&item1=keyboard&item2=mouse&item3=&cost1=1000&cost2=500&cost3=&total=1500
它给了我以下的错误
我无法使用此脚本使用google脚本将数据输入到模板id为TEMPLATE_ID
的google文档模板中。我的python代码运行良好。请帮助我解决这个问题
目前没有回答
相关问题 更多 >
编程相关推荐