Google Script custom function to return rich text

So…I’ve built a custom function that processes values from a Gsheet and return them in a single cell. In brief, the source sheet has one column containing places, one containing services rendered at these places and another one containing dates of conclusion. The custom function gathers all the services rendered at the same place on a determined date. It is already working and almost giving me the expected return.

Returned string:
-> Place1:
– Service1;
– Service2.

-> Place2:
– Service3;
– Service4.

Desired return:
-> Place1:
– Service1;
– Service2.

-> Place2:
– Service3;
– Service4.

I’ve already searched for RichTextValue usage, but I don’t know if it is because I’m using as a return of a custom function or it is me that does not know how to use it correctly, but it’s not working. Here’s a sample code that I’m using to test the function:

function test(){
  var bold=SpreadsheetApp.newTextStyle().setBold(true).build();
  var test=SpreadsheetApp.newRichTextValue().setText("test").setTextStyle(0,2,bold).build().getText();
  return test;
  }

It’s kind of obvious, one would say “getText()” returns the string contained in the RichTextValue, so it won’t return a RichText, I know. So I tried “getRuns().join()” (joined because getRuns returns array) after “build()” and I get this result: “com.google.apps.maestro.server.beans.trix.impl.RichTextValueApiAdapter@2d54d6e,com.google.apps.maestro.server.beans.trix.impl.RichTextValueApiAdapter@4c67374a”.

So my question is, Is there a “getRichText()” as a return for my custom function or any other way to do this?

Thanks in advance.

1

It is actually NOT possible to return formatted data on custom functions, only raw values.

You can work with conditional formatting or make a custom menu or button so ou can run a function that builds the values and its formats.
Something like this:

// on its startup (Simple trigger) it runs the onOpen function that creates a custom menu and adds a menu item that when clicked runs the function "appendValuestoSheet"
function onOpen(){
  SpreadsheetApp.getUi()
  .createMenu("My Custom Menu")
  .addItem("Calculate Values", "appendValuestoSheet")
  .addToUi();
}

function appendValuestoSheet(){
  var ss = SpreadsheetApp.getActiveSpreadsheet(); // get the current open sheet
  var fontWeights = []; // empty array to be filled with formatting strings (Its size will be based on the newData array size
  var newData = [
      ["Place1", "Service1", "Service2"],
      ["Place1", "Service1", "Service2"]
    ];

  // iterate the new values to add to sheet
  newData.forEach(function(row,rowIndex){
    var newFontWeightsRow, fontWeight;

    // Set bold format only to the first row
    if(rowIndex === 0){
      fontWeight = "bold";
    } else {
      fontWeight = "normal";
    }
    // buids a new row with the formats, in this case only the first row will be bold;
    newFontWeightsRow = row.map(function(){return fontWeight});

    // push the new formats row to the array;
    fontWeights.push(newFontWeightsRow);
  });

   // "fontWeights" array has the same size as "newData" array
  ss.getSheetByName("newDataTab")
    .getRange(1, 1, newData.length, newData[0].length) // adds data starting on the first row and col;
    .setFontWeights(fontWeights) // sets the new formats to the range
    .setValues(newData); // sets the new data to the range
}

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật