Home > Software engineering >  Removing leading and trailing quotation marks in Google Sheets / Apps script
Removing leading and trailing quotation marks in Google Sheets / Apps script

Time:07-20

I am writing a script to populate a cell with some information for a mailer. I'm fairly new to this, so am guessing the coding isn't perfect. However, all I really need to achieve is to get a block of text - and it's pretty much there.

The problem is, that when it returns the text it adds a qutoation at start and at the end.

Can someone let me know how to return the text without this.

function MailerText(strMailer, strName) {
  
  if (strMailer === undefined || strMailer === "Ignore") {return ""};
  
  let  varBody
  let  ss = SpreadsheetApp.getActiveSpreadsheet();
  var formS = ss.getSheetByName("Actions");

  
  if (strMailer == 'A Style English') {varBody = formS.getRange('C1').getValue(); varSalutation = formS.getRange('B1').getValue();}
  else if (strMailer == 'A Style German - Female') {varBody = formS.getRange('C2').getValue(); varSalutation = formS.getRange('B2').getValue();};
  
  if (varBody == undefined) {return ""};
  return varSalutation   ' '   strName   ','   "\n"   "\n"   varBody; 

}

As requested, here are a few screen shots of the issue:

Image 1: The function call from the cell

Image 2: How it looks in Sheets after the function call

Image 3: What you get when you copy/paste the text into something.

The function call from the cell

How it looks in Sheets

When you copy the cell and paste it into something, you have the quotation marks

CodePudding user response:

In this case after researching for a while it seems that whenever Sheets detects that there are special characters or line breaks you will get the quotation marks added when the text is copied, there is a similar post about this behavior and it contains a good workaround if you don't mind copying the text to a different cell then you can try this formula on another cell:

=SUBSTITUTE(C609,char(10),char(13))

This would basically copy the text without the special characters on it and when copy/pasted from the cell where the formula is added then you will see that the quotations will no longer be there.

  • Related