我創建了一個腳本,可以將 xlsx 檔案匯入到 google sheet 并且它當前作業,但我需要修改它以獲取整個作業表而不使用特定范圍并將其粘貼為普通文本,因為當前輸出文本有粗體和大字體,有人可以幫我修改或更改我的腳本需要什么?
我的劇本
const sourceValues = sourceSheet.getRange("B1:V5231").getValues();
const target = SpreadsheetApp.openById(ID).getSheetByName('sheetname');
target.getRange(target.getLastRow() 1, 1, sourceValues.length, sourceValues[0].length).setValues(sourceValues);
謝謝!
uj5u.com熱心網友回復:
建議
如果我清楚地理解了您的問題,您希望動態獲取作業表上包含.xlsx資料的范圍,而不是使用該方法明確使用特定范圍getRange()。
您可以嘗試使用該getDataRange()方法,因為它會回傳與作業表上存在資料的維度相對應的范圍。
至于將資料正常粘貼為不帶格式的文本,您可以嘗試使用getDisplayValues()而不是使用,getValues()因為這會將值作為String物件回傳。
[更新]
如果getDisplayValues()不洗掉文本格式,您也可以clearFormats按照此現有帖子使用該方法。此方法將清除內容和/或格式。請參閱下面的示例用法:
腳本
const sourceValues = sourceSheet.getRange("B1:V5231").getValues();
const target = SpreadsheetApp.openById(ID).getSheetByName('sheetname');
target.getRange(target.getLastRow() 1, 1, sourceValues.length, sourceValues[0].length).setValues(sourceValues);
target.clearFormats();
該方法將在設定值后洗掉目標
clearFormats作業表上文本的格式。
參考:
- getDataRange()方法
- getDisplayValues()方法
- clearFormats()方法
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/486510.html
標籤:谷歌应用脚本 谷歌表格 谷歌表格 API xlsx
