Utilities.parseCsv(csv,“;")也以逗号分隔 [英] Utilities.parseCsv(csv, ";") also splits on commas

查看:133
本文介绍了Utilities.parseCsv(csv,“;")也以逗号分隔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用以;分隔的csv文件.在某些领域,我们有逗号,但是没关系.

I want to work with a csv file delimited by ;. In some fields, we have commas, but it's ok.

示例行如下(请注意,一列中有一个逗号):

An example line is as follows (notice there is a comma in one column):

01.02.2018;01.02.2018;"SEPA-Dauerauftrag an";Maier, Herbert;RINP Dauerauftrag Miete Kräpelinstr. 61;DE45700100800225067803;PBNKDEFFXXX;;;;;;;;;-900,00;;EUR

我使用的Google Apps脚本代码如下;

The Google Apps Script code that I use is as follows;

function importCSVFromGoogleDrive() {
  var ss = SpreadsheetApp.openById('<wb id>');
  var outputSheet = ss.getSheetByName('import');

  var fileIterator = DriveApp.getFilesByName("Kontoumsaetze_220_320895600_20180728_155842_DEV.csv");
  var csv = fileIterator.next().getBlob().getDataAsString('ISO-8859-1');
  Logger.log(csv);
  var csvData = Utilities.parseCsv(csv, ";");
  Logger.log("-------------");
  Logger.log(csvData);
}

我只想使用;分开,但我无法实现. GAS还会继续分隔逗号,这会破坏我的程序.

I just want to separate using ;, but I can not achieve it. GAS keeps separating also the comma and this breaks my program.

  1. 如果我告诉;,为什么它被,隔开.
  2. 如何解决此问题?
  1. Why is it separating by , if I am telling ;.
  2. How can I fix the issue?

以下是日志(在Mayer, Herber中使用逗号分隔):

Here are the logs (it separates using the comma, in Mayer, Herber):

[18-07-29 18:42:22:922 CEST] 01.02.2018;01.02.2018;"SEPA-Dauerauftrag an";Maier, Herbert;RINP Dauerauftrag Miete Kräpelinstr. 61;DE45700100800225067803;PBNKDEFFXXX;;;;;;;;;-900,00;;EUR
[18-07-29 18:42:22:923 CEST] -------------
[18-07-29 18:42:22:924 CEST] [[01.02.2018, 01.02.2018, SEPA-Dauerauftrag an, Maier, Herbert, RINP Dauerauftrag Miete Kräpelinstr. 61, DE45700100800225067803, PBNKDEFFXXX, , , , , , , , , -900,00, , EUR]]

推荐答案

当显示对象数据时,这是Apps脚本Logger的失败.

This is a failure of the Apps Script Logger when it comes to displaying object data.

使用此代码:

function csvParseSemiOnly() {
  var csv = '01.02.2018;01.02.2018;"SEPA-Dauerauftrag an";Maier, Herbert;RINP Dauerauftrag Miete Kräpelinstr. 61;DE45700100800225067803;PBNKDEFFXXX;;;;;;;;;-900,00;;EUR';
  var csvData = Utilities.parseCsv(csv, ";");
  console.log({message: "Parsed input", input: csv, output: csvData});
  Logger.log(csvData[0][3]);
}

我得到这个结果:

通常,如果您需要检查对象(尤其是嵌套对象),或者从最近执行的脚本中查看日志记录活动,则建议使用Stackdriver Logging功能.

In general, I recommend using the Stackdriver Logging functionality if you need to inspect objects, especially if nested, or review logging activity from more than the most recent script execution.

您应该查看Apps脚本指南以进行日志记录:
https://developers.google.com/apps-script/guides/logging

You should review the Apps Script guide to logging:
https://developers.google.com/apps-script/guides/logging

值得注意的是,要查看Stackdriver中的日志,您必须能够访问脚本的Google Cloud Platform项目.

Of note, to review logs in Stackdriver you must be able to access the script's Google Cloud Platform project.

这篇关于Utilities.parseCsv(csv,“;")也以逗号分隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆