如何在 Google 应用程序脚本中停止 foreach 循环
How to stop foreach loop in Google apps script
我需要从 RSS URL.
生成文档文件
https://cdn.feedcontrol.net/1830/2857-8L5Ntr0N5l5Xf.xml
我在 Tanaike 的帮助下完成了 。
function myFunction1() {
const url = "https://cdn.feedcontrol.net/1830/2857-8L5Ntr0N5l5Xf.xml";
const data = UrlFetchApp.fetch(url).getContentText();
const root = XmlService.parse(data).getRootElement();
const ns1 = root.getNamespace();
const ns2 = XmlService.getNamespace("http://purl.org/rss/1.0/modules/content/");
root.getChild("channel", ns1).getChildren("item", ns1).forEach(e => {
Drive.Files.insert({title: e.getChild("title", ns1).getValue(), mimeType: MimeType.GOOGLE_DOCS}, HtmlService.createHtmlOutput(e.getChild("encoded", ns2).getValue()).getBlob());
});
}
但是,当检索 RSS 中的所有 10 个项目时,它会重复,因为 RSS 只创建 5 个新项目。
所以我想在第一个项目上创建 DOC 文件后停止。
请帮帮我!
const items = root.getChild("channel", ns1).getChildren("item", ns1);
for (let i = 0; i < 5; i++) {
const e = items[i];
Drive.Files.insert({title: e.getChild("title", ns1).getValue(), "parents": [{'id':folderlocid}], mimeType: MimeType.GOOGLE_DOCS}, HtmlService.createHtmlOutput(e.getChild("encoded", ns2).getValue()).getBlob());
}
我需要从 RSS URL.
生成文档文件https://cdn.feedcontrol.net/1830/2857-8L5Ntr0N5l5Xf.xml
我在 Tanaike 的帮助下完成了
function myFunction1() {
const url = "https://cdn.feedcontrol.net/1830/2857-8L5Ntr0N5l5Xf.xml";
const data = UrlFetchApp.fetch(url).getContentText();
const root = XmlService.parse(data).getRootElement();
const ns1 = root.getNamespace();
const ns2 = XmlService.getNamespace("http://purl.org/rss/1.0/modules/content/");
root.getChild("channel", ns1).getChildren("item", ns1).forEach(e => {
Drive.Files.insert({title: e.getChild("title", ns1).getValue(), mimeType: MimeType.GOOGLE_DOCS}, HtmlService.createHtmlOutput(e.getChild("encoded", ns2).getValue()).getBlob());
});
}
但是,当检索 RSS 中的所有 10 个项目时,它会重复,因为 RSS 只创建 5 个新项目。 所以我想在第一个项目上创建 DOC 文件后停止。
请帮帮我!
const items = root.getChild("channel", ns1).getChildren("item", ns1);
for (let i = 0; i < 5; i++) {
const e = items[i];
Drive.Files.insert({title: e.getChild("title", ns1).getValue(), "parents": [{'id':folderlocid}], mimeType: MimeType.GOOGLE_DOCS}, HtmlService.createHtmlOutput(e.getChild("encoded", ns2).getValue()).getBlob());
}