在下面的示例中,我將檔案夾和 ss 留空。
想法是檢索在代碼中指定的 url 的檔案中找到的文本“新興市場(”之后的數字,然后將其插入到指定的谷歌表中的單元格 b2 中。
沒有收到任何錯誤,但代碼不起作用。感謝您的幫助。新手來了。
謝謝!
const FOLDER_ID = ""; //Folder ID of all PDFs
const SS = "";//The spreadsheet ID
const SHEET = "MSCI";//The sheet tab name
function OpenFile() {
var url = "https://www.yardeni.com/pub/mscipe.pdf";
var blob = UrlFetchApp.fetch(url).getBlob();
var resource = {
title: blob.getName(),
mimeType: blob.getContentType()
};
// Enable the Advanced Drive API Service
var file = Drive.Files.insert(resource, blob, {ocr: true, ocrLanguage: "en"});
// Extract Text from PDF file
var doc = DocumentApp.openById(file.id);
var text = doc.getBody().getText();
return text;
const identifier = {
start: `Emerging Markets (`,
start_include: false,
end: `)`,
end_include: false
};
let results = getDocItems(docID, identifier);
return results;
}
function importToSpreadsheet(results){
const sheet = SpreadsheetApp.openById(SS).getSheetByName(SHEET);
var cell = sheet.getRange("B2");
cell.setValue(results);
}
uj5u.com熱心網友回復:
我看到兩個函式:OpenFile()and importToSpreadsheet(results),但沒有看到呼叫函式的行。
只是一個猜測。也許您需要在代碼末尾添加這一行:
importToSpreadsheet(OpenFile());
更新
該OpenFile()函式為您提供所有文本。如果您只需要 ' Emerging Markets ( ' 和 ' ) '之間的文本部分,您可以通過這種方式將其剪掉:
var text = OpenFile(); // all text
var part = text.split('Emerging Markets (')[1].split(')')[0]; // a part between 'Emerging Markets (' and ')'
importToSpreadsheet(part); // put the part in the cell
從const identifier = {...到的行...return results;是多余的。可能它們取自另一個樣本,不屬于此代碼。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/358810.html
標籤:谷歌应用程序脚本
