我正在表格中运行应用程序脚本,通常会将Gmail中的附件引入到Google表格中。它在大多数情况下都有效,但是当数据包含双引号时,它会生成解析错误
我的源数据像这样成千上万行:
",05/02/2019,3:13,151:22,5:30,08:11,Enroute,C000003251,219688X01232019,BIN11,,Item1,08:11,0:05,,,0:00
Worker2,34:51,869:25,110:00,"Completed: 168
Suspended: 43
Skipped: 41
",05/02/2019,3:13,151:22,5:30,08:17,OnSite,C000003251,219688X01232019,BIN11,,Item1,,,08:17,0:16,0:30
Worker2,34:51,869:25,110:00,"Completed: 168
Suspended: 43
Skipped: 41
",05/02/2019,3:13,151:22,5:30,08:34,Complete,C000003251,219688X01232019,BIN11,,Item1,,,,,0:00
Worker2,34:51,869:25,110:00,"Completed: 168
Suspended: 43
Skipped: 41
",05/02/2019,3:13,151:22,5:30,08:42,Enroute,C000003252,219689X01232019,BIN11,,Item1,08:42,0:00,,,0:00
Worker2,34:51,869:25,110:00,"Completed: 168
Suspended: 43
Skipped: 41
",05/02/2019,3:13,151:22,5:30,08:42,OnSite,C000003252,219689X01232019,BIN11,,Item1,,,08:42,0:14,0:30
Worker2,34:51,869:25,110:00,"Completed: 168
Suspended: 43
Skipped: 41
",05/02/2019,3:13,151:22,5:30,08:56,Complete,C000003252,219689X01232019,BIN11,,Item1,,,,,0:00
Worker2,34:51,869:25,110:00,"Completed: 168
Suspended: 43
Skipped: 41
",05/02/2019,3:13,151:22,5:30,08:57,Enroute,C000003253,219690X01232019,BIN11,,Item1,08:57,0:05,,,0:00
attachment.setContentTypeFromExtension();
if (attachment.getContentType() === "text/csv") {
var sheet =
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Month1");
var csvData = Utilities.parseCsv(attachment.getDataAsString(), ",");
sheet.clearContents().clearFormats();
sheet.getRange(1, 1, csvData.length,
csvData[0].length).setValues(csvData);
}
我收到此错误:“无法解析文本”,我似乎无法弄清楚如何忽略或删除源数据中的双引号
提前谢谢!
答案 0 :(得分:0)
您可以使用这两个公式中的任意一个从数据集中删除所有双引号
=ARRAYFORMULA(REGEXREPLACE(A1:A, """", ""))
=ARRAYFORMULA(SUBSTITUTE(A1:A, """", ""))
,或者如果可以选择,则可以使用 CTRL + H 并将其完全删除。
答案 1 :(得分:0)
问题似乎已经解决