Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Initial work is done by MattyKing
- */
- /**
- * Allows inline text formatting.
- * Example: =TEXTFORMAT(0,"this is serif bold", "serifbold")&" "&"normal text"
- * @param {type} type Array behaviour for types. 0 = All the text in same type, 1 = You need to profide same length typeface array. 2 = Returns available types
- * @param {text} string Any text or cell reference with text.
- * @param {typeface} typeface Typefaces: serifbold, serifbolditalic, sans, sansitalic, sansbold, sansbolditalic, script
- * @customfunction
- */
- function TEXTFORMAT(type, string, typeface) {
- const input = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz !@#$%^&*()_+{}:<>?1234567890-=[];,./|".split("");
- const outputs = {
- serifbold: "๐๐๐๐๐๐ ๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐ ๐ก๐ข๐ฃ๐ค๐ฅ๐ฆ๐ง๐จ๐ฉ๐ช๐ซ๐ฌ๐ญ๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ",
- serifbolditalic: "๐จ๐ฉ๐ช๐ซ๐ฌ๐ญ๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ๐ด๐ต๐ถ๐ท๐ธ๐น๐บ๐ป๐ผ๐ฝ๐พ๐ฟ๐๐๐๐๐๐ ๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐",
- sans: "๐ ๐ก๐ข๐ฃ๐ค๐ฅ๐ฆ๐ง๐จ๐ฉ๐ช๐ซ๐ฌ๐ญ๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ๐ด๐ต๐ถ๐ท๐ธ๐น๐บ๐ป๐ผ๐ฝ๐พ๐ฟ๐๐๐๐๐๐ ๐๐๐๐๐๐๐๐๐๐๐๐๐๐",
- sansitalic: "๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐ ๐ก๐ข๐ฃ๐ค๐ฅ๐ฆ๐ง๐จ๐ฉ๐ช๐ซ๐ฌ๐ญ๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ๐ด๐ต๐ถ๐ท๐ธ๐น๐บ๐ป",
- sansbold: "๐๐๐๐๐๐๐๐๐๐๐๐๐ ๐ก๐ข๐ฃ๐ค๐ฅ๐ฆ๐ง๐จ๐ฉ๐ช๐ซ๐ฌ๐ญ๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ๐ด๐ต๐ถ๐ท๐ธ๐น๐บ๐ป๐ผ๐ฝ๐พ๐ฟ๐๐๐๐๐๐ ๐๐",
- sansbolditalic: "๐ผ๐ฝ๐พ๐ฟ๐๐๐๐๐๐ ๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐ ๐ก๐ข๐ฃ๐ค๐ฅ๐ฆ๐ง๐จ๐ฉ๐ช๐ซ๐ฌ๐ญ๐ฎ๐ฏ",
- script: "๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐ ๐ก๐ข๐ฃ๐ค๐ฅ๐ฆ๐ง๐จ๐ฉ๐ช๐ซ๐ฌ๐ญ๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ๐ด๐ต๐ถ๐ท๐ธ๐น๐บ๐ป๐ผ๐ฝ๐พ๐ฟ๐๐๐๐",
- };
- //Returns the availible typefaces.
- if (type == 2) {
- return Object.entries(outputs)
- }
- //Converts to array. So next logic is always based on an array.
- if (!Array.isArray(string)) {
- string = [string];
- }
- //Flatten. Because sheets gives a 2d array and that is not needed.
- string = string.flat();
- if (type == 1 && !Array.isArray(typeface)) {
- typeface = [typeface];
- typeface = typeface.flat();
- //Defaults back to the first entrie in the typeface array.
- } else if (type == 0 && Array.isArray(typeface)) {
- typeface = typeface[0];
- }
- //Creates an array for each converted string in the string a
- return string.map((str, i) => {
- let output;
- //Get the correct output typeface
- if (type == 0) {
- output = outputs[typeface]
- } else {
- output = outputs[typeface[i]]
- }
- return str.split('')
- .map(e => [e, 2 * input.indexOf(e)])
- .map(e => {
- if (e[1] < output.length) {
- return output.substring(e[1], e[1] + 2)
- } else {
- return e[0]
- }
- }).join('')
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement