Prabhu Paul
Prabhu Paul

Reputation: 188

Extra double quotes in csv coming in Google Sheets Apps Script Web App

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

Pls find my sheet here, below are the Cell Values


C1 = tdsyltt = 'ఈరోజు ( బుధవారం )  క్విజ్ సిలబస్' ;

C2 = tdsyl = 'హబక్కూకు 1 & యాకోబు 2, 3' ;

C4 = document.getElementById("tdsyltt).innerHTML = tdsyltt ;

C5 = document.getElementById("tdsyl").innerHTML = tdsyl ;

And using my published URL I have developed a web app

code.gs

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=csv").getContentText()).setMimeType(ContentService.MimeType.JAVASCRIPT);

In the web app output 1st line is ok,

but for 2nd, 3rd and 4th line there are Extra 2 Apostrophes coming at the starting and ending of the lines.

Here is My Web App

enter image description here

How to fix this ..?

Upvotes: 0

Views: 532

Answers (2)

user20685610
user20685610

Reputation:

Try a way to solve this by changing the spreadsheet Publishing Format from csv to tsv then it will work.

Code.gs

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);

Upvotes: 0

Tanaike
Tanaike

Reputation: 201513

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:

Upvotes: 2

Related Questions