Skip to content

Instantly share code, notes, and snippets.

@bcooksey
Created June 29, 2022 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bcooksey/1c90535d4fc87b19510fd01e040d8b65 to your computer and use it in GitHub Desktop.
Save bcooksey/1c90535d4fc87b19510fd01e040d8b65 to your computer and use it in GitHub Desktop.
Google Sheets with Macro to Reformat and Bold Text in a Cell
/** @OnlyCurrentDoc */
function ReformatandBold() {
var spreadsheet = SpreadsheetApp.getActive();
var cellText = spreadsheet.getCurrentCell().getValue();
var newCellText = '';
var subCompetencies = [];
cellText.split('[').forEach((element) => {
if (!element){
return;
}
var subsplits = element.split('] ');
subCompetencies.push(subsplits[0].trim());
newCellText += subsplits[0].trim() + "\n" + subsplits[1].trim() + "\n\n";
});
newCellText = newCellText.trim();
var newRichValue = SpreadsheetApp.newRichTextValue().setText(newCellText);
subCompetencies.forEach((subComp) => {
var i = newCellText.search(subComp);
newRichValue.setTextStyle(i, i+subComp.length, SpreadsheetApp.newTextStyle()
.setBold(true)
.build())
});
spreadsheet.getCurrentCell().setRichTextValue(newRichValue.build());
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment