参考:未定义
功能lastrows2
正常工作。但是,convert_txt_gsheets投掷
参考文献:未定义拆分
哪个终止整个过程,并阻止Lastrow2参与。分裂使我非常困惑。
function pricing() {
convert_txt_gsheets();
lastrow2();
}
function convert_txt_gsheets() {
var source = SpreadsheetApp.openById('ID1').getSheetByName('Daily Report');
var targetrange = source.getRange(2, 1, source.getLastRow(), source.getLastColumn());
targetrange.clear();
var file = DriveApp.getFileById('ID2');
var body = file.getBlob().getDataAsString().split(/\r/);
var result = body.map(split(/|/))
// vvv
.map(row => row.map(cell => cell.replaceAll(`"`, ``)));
SpreadsheetApp.getActive().getSheetByName('Daily Report').getRange(1, 1, result.length, result[0].length).setValues(result);
return;
}
function lastrow2() {
var source = SpreadsheetApp.openById('ID1').getSheetByName('Daily Report');
var target = SpreadsheetApp.openById('ID1').getSheetByName('Permanent Record');
var target = target.getRange(target.getLastRow()+1, 1, source.getLastRow(), source.getLastColumn());
var rangeValues = source.getRange(2, 1, source.getLastRow(), source.getLastColumn()).getValues();
target.setValues(rangeValues);
}
这是从TXT提取的示例数据。
COLUMN0|COLUMN1|COLUMN2|COLUMN3|COLUMN4|COLUMN5|COLUMN6|COLUMN7|COLUMN8
"Rocketship"|"5.99"|"5.39"|"5.39"|""|"5.39"|"5.39"|"7.5.2022"|"william"
修改的代码
function pricing() {
convert_txt_gsheets();
lastrow2();
}
function convert_txt_gsheets() {
var source = SpreadsheetApp.openById('ID1').getSheetByName('Daily Report');
var targetrange = source.getRange(2, 1, source.getLastRow(), source.getLastColumn());
targetrange.clear();
var file = DriveApp.getFileById('ID2');
let body = file.getBlob().getDataAsString().split('\r'); // split into rows
let results = body.map( row => row.split('|') ); // split into columns
results = result.map( col => col.map( cell => cell.replaceAll(`"`, ``)));
SpreadsheetApp.getActive().getSheetByName('Daily Report').getRange(1, 1, result.length, result[0].length).setValues(result);
return;
}
function lastrow2() {
var source = SpreadsheetApp.openById('ID1').getSheetByName('Daily Report');
var target = SpreadsheetApp.openById('ID1').getSheetByName('Permanent Record');
var target = target.getRange(target.getLastRow()+1, 1, source.getLastRow(), source.getLastColumn());
var rangeValues = source.getRange(2, 1, source.getLastRow(), source.getLastColumn()).getValues();
target.setValues(rangeValues);
}
The function Lastrows2
works properly. However, the Convert_txt_gsheets throws
ReferenceError: split is not defined
which terminates the whole thing, and stops lastrow2 from ever engaging. Splits confuse me immensely.
function pricing() {
convert_txt_gsheets();
lastrow2();
}
function convert_txt_gsheets() {
var source = SpreadsheetApp.openById('ID1').getSheetByName('Daily Report');
var targetrange = source.getRange(2, 1, source.getLastRow(), source.getLastColumn());
targetrange.clear();
var file = DriveApp.getFileById('ID2');
var body = file.getBlob().getDataAsString().split(/\r/);
var result = body.map(split(/|/))
// vvv
.map(row => row.map(cell => cell.replaceAll(`"`, ``)));
SpreadsheetApp.getActive().getSheetByName('Daily Report').getRange(1, 1, result.length, result[0].length).setValues(result);
return;
}
function lastrow2() {
var source = SpreadsheetApp.openById('ID1').getSheetByName('Daily Report');
var target = SpreadsheetApp.openById('ID1').getSheetByName('Permanent Record');
var target = target.getRange(target.getLastRow()+1, 1, source.getLastRow(), source.getLastColumn());
var rangeValues = source.getRange(2, 1, source.getLastRow(), source.getLastColumn()).getValues();
target.setValues(rangeValues);
}
This is the example data that is being pulled from txt.
COLUMN0|COLUMN1|COLUMN2|COLUMN3|COLUMN4|COLUMN5|COLUMN6|COLUMN7|COLUMN8
"Rocketship"|"5.99"|"5.39"|"5.39"|""|"5.39"|"5.39"|"7.5.2022"|"william"
MODIFIED CODE
function pricing() {
convert_txt_gsheets();
lastrow2();
}
function convert_txt_gsheets() {
var source = SpreadsheetApp.openById('ID1').getSheetByName('Daily Report');
var targetrange = source.getRange(2, 1, source.getLastRow(), source.getLastColumn());
targetrange.clear();
var file = DriveApp.getFileById('ID2');
let body = file.getBlob().getDataAsString().split('\r'); // split into rows
let results = body.map( row => row.split('|') ); // split into columns
results = result.map( col => col.map( cell => cell.replaceAll(`"`, ``)));
SpreadsheetApp.getActive().getSheetByName('Daily Report').getRange(1, 1, result.length, result[0].length).setValues(result);
return;
}
function lastrow2() {
var source = SpreadsheetApp.openById('ID1').getSheetByName('Daily Report');
var target = SpreadsheetApp.openById('ID1').getSheetByName('Permanent Record');
var target = target.getRange(target.getLastRow()+1, 1, source.getLastRow(), source.getLastColumn());
var rangeValues = source.getRange(2, 1, source.getLastRow(), source.getLastColumn()).getValues();
target.setValues(rangeValues);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在
var result = body.map(split(/|/))
中犯了一个错误。尝试一下。替换:
这是我的测试集。适当地更换上面的行。
执行日志
我不确定日期,但是当您setValues()()时,其他人会转换为适当的类型。
You made a mistake in
var result = body.map(split(/|/))
. Try this.Replace:
This is my test set. Replace the lines above as appropriate.
Execution log
I'm not sure about the date but the others will be converted to their appropriate type when you setValues().