异常:数据中的列数与范围内的列数不匹配。 - 问题
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);
}
我可以在上述代码方面寻求帮助吗?功能Lastrows2正常工作。但是,convert_txt_gsheets抛出异常“异常:数据中的列数与范围内的列数不匹配。数据具有1个,但范围有9个。Convert_TXT_GSHEETS“终止整个内容,并停止Lastrow2,并从Evers中停止Lastrow2。参与。
这是从TXT提取的示例数据。
Column0 | Column1 | Column2 Column3 | Column4 | Column5 Column6 | Column6 | Column7 | Column7 | “ |
---|---|---|---|---|---|---|---|---|
Rocketship” | “ 5.99”“ 5.39” | “ 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');
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);
}
Could I ask for help with the above code? The function Lastrows2 works properly. However, the Convert_txt_gsheets throws exception "Exception: The number of columns in the data does not match the number of columns in the range. The data has 1 but the range has 9. convert_txt_gsheets" which terminates the whole thing, and stops lastrow2 from ever engaging.
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" |
Edit I modified the example and the original code. The error currently received is
ReferenceError: split is not defined
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您几乎很好,问题在这里:
这里我所做和测试的功能:
You are almost good, the problem is here :
Here the function I did and tested :