Created
January 2, 2020 14:47
-
-
Save jiristepan/6fecec0aedd2937f380b42feee1e3060 to your computer and use it in GitHub Desktop.
Nahrazeni mezer za pevne ve spreadhseetu
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
var ss = SpreadsheetApp.getActiveSpreadsheet(); | |
var space = String.fromCharCode(32); | |
var nonBreakingSpace = String.fromCharCode(160); | |
//var nonBreakingSpace = "_"; // pro test | |
//hlavni funkce. Provede nahrazeni ve vsech bunkach | |
function replaceActiveSheet(){ | |
var sheet = ss.getActiveSheet() | |
var range =sheet.getDataRange(); | |
var values = range.getValues() | |
for(var r=0;r<values.length;r++){ | |
for(var c=0;c<values[0].length;c++){ | |
if( values[r][c] != "") { | |
values[r][c] = replaceSpacesInString(values[r][c]) | |
} | |
} | |
} | |
range.setValues(values); | |
} | |
//nahrazeni v jednom stringu | |
function replaceSpacesInString(text) { | |
var chars = [ "a", "A", "i", "I", "s", "S", "z", "Z", "v", "V", "k", "K", "o", "O", "u", "U"]; | |
for(var i=0;i<chars.length;i++){ | |
var char=chars[i] | |
text = text.replace(space + char + space, space + char + nonBreakingSpace ); | |
}; | |
return text; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment