Created
June 29, 2022 20:42
-
-
Save bcooksey/1c90535d4fc87b19510fd01e040d8b65 to your computer and use it in GitHub Desktop.
Google Sheets with Macro to Reformat and Bold Text in a Cell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** @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