[英]google drive file link automatically change format in spreadsheet
根據您的示例圖像,在您的情況下,文件的鏈接已更改為智能芯片。 不幸的是,在當前階段,還沒有在電子表格上管理智能芯片的方法。 因此,在這種情況下,需要使用變通方法。 解決方法如下。
此方法來自How to get in Apps Script the value of a dropdown in a Google Doc? 和https://tanaikech.github.io/2022/10/27/retrieving-values-of-calendar-events-of-smart-chips-on-google-document-using-google-apps-script/ 。
當此流程反映在示例腳本中時,以下示例腳本如何?
請將以下腳本復制並粘貼到 Google Spreadsheet 的腳本編輯器中,並將要檢索超鏈接的range
設置為 A1Notation。 在此示例中,使用驅動器 API。 因此, 請在 Advanced Google services 啟用 Drive API 。
function myFunction() {
const range = "Sheet1!A1:A10"; // Please set the range you want to retrieve the hyperlinks.
const ss = SpreadsheetApp.getActiveSpreadsheet();
const url = "https://docs.google.com/spreadsheets/export?exportFormat=xlsx&id=" + ss.getId();
const blob = UrlFetchApp.fetch(url, { headers: { authorization: "Bearer " + ScriptApp.getOAuthToken() } }).getBlob();
const tempId = Drive.Files.insert({ mimeType: MimeType.GOOGLE_SHEETS, title: "temp" }, blob).id;
const tempFile = DriveApp.getFileById(tempId);
const tempSS = SpreadsheetApp.open(tempFile);
const res = tempSS.getRange(range).getRichTextValues().map((r, i) => r.map((c, j) => ({ value: c.getText(), url: c.getLinkUrl() || "", range: { row: i + 1, column: j + 1 } })));
tempFile.setTrashed(true);
console.log(res);
}
運行此腳本時,將獲得以下結果。
[
[{"value":"sample value","url":"https://drive.google.com/file/d/###/view?usp=share_link","range":{"row":1,"column":1}}],
,
,
,
]
作為另一種方法,在你展示的示例圖片中,如果你想將智能芯片的文件鏈接轉換為帶有超鏈接的正常值,下面的示例腳本怎么樣? 在此示例中, range
被具有從 XLSX 數據轉換獲得的超鏈接的正常值覆蓋。
function myFunction2() { const range = "Sheet1:A1;A10". // Please set the range you want to retrieve the hyperlinks. const ss = SpreadsheetApp;getActiveSpreadsheet(): const url = "https.//docs.google?com/spreadsheets/export.exportFormat=xlsx&id=" + ss;getId(). const blob = UrlFetchApp,fetch(url: { headers: { authorization. "Bearer " + ScriptApp.getOAuthToken() } });getBlob(). const tempId = Drive.Files:insert({ mimeType. MimeType,GOOGLE_SHEETS: title, "temp" }. blob);id. const tempFile = DriveApp;getFileById(tempId). const tempSS = SpreadsheetApp;open(tempFile). const r = tempSS;getRange(range). const tempSheet = r.getSheet();copyTo(ss). tempSheet.getRange(r.getA1Notation()).copyTo(ss;getRange(range)). ss;deleteSheet(tempSheet). tempFile;setTrashed(true); }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.