Home > Back-end >  Extra double quotes in csv coming in Google Sheets Apps Script Web App
Extra double quotes in csv coming in Google Sheets Apps Script Web App

Time:11-03

In my google sheet I have some data in it. Later I published my sheet as .csv format.

Pls find enter image description here

How to fix this ..?

CodePudding user response:

Modification points:

  • In this case, how about directly retrieving the values from Spreadsheet using Spreadsheet service instead of UrlFetchApp.fetch("https://docs.google.com/spreadsheets/d/e/2PACX-1vReY-tDEwKYjTiSjsfAN42qjFUwMv_OD3_64bFdGrgL-2p3otc13elLcCq3pkb5xqhTA-bW3QXobpqh/pub?gid=1861615717&single=true&range=c1:c5&output=csv").getContentText()? I thought that the reason of your current issue might be due to exporting the Spreadsheet as CSV data. When the Spreadsheet service is used, the values can be retrieved.

    • In your previous question, I said "In this answer, your Spreadsheet is used. Of course, you can directly set the script in Web Apps.". Ref In your this question, I thought that this can be used.
  • In your sample Spreadsheet, document.getElementById("tdsyltt).innerHTML = tdsyltt ; is required to be document.getElementById("tdsyltt").innerHTML = tdsyltt ;. Please be careful about this.

When these points are reflected in your script, how about the following modification?

Modified script:

const doGet = _ => {
  const spreadsheetId = "###"; // Please set your Spreadsheet ID.
  
  const ss = SpreadsheetApp.openById(spreadsheetId);
  const sheet = ss.getSheetByName("SYLLABUSC");
  const html = sheet.getRange("C1:C6").getDisplayValues().filter(([c]) => c).join("\n");
  
  // console.log(html); // When you directly run this function with the script editor, you can see the created value in the log.
  
  return ContentService.createTextOutput(html).setMimeType(ContentService.MimeType.JAVASCRIPT);
}
  • From your Spreadsheet, in this sample script, I used "C1:C6" of "SYLLABUSC" sheet. So, please modify this for your actual situation.

Note:

CodePudding user response:

I tried a way to solve this by changing the spreadsheet publishing format from csv to tsv then it's working.

Modified code.gs file

const doGet = _ => ContentService.createTextOutput(UrlFetchApp.fetch("https://docs.google.com/spreadsheets/d/e/2PACX-1vReY-tDEwKYjTiSjsfAN42qjFUwMv_OD3_64bFdGrgL-2p3otc13elLcCq3pkb5xqhTA-bW3QXobpqh/pub?gid=1861615717&single=true&range=c1:c5&output=tsv").getContentText()).setMimeType(ContentService.MimeType.JAVASCRIPT);
  • Related