LANG SELRCT

Apps Script Reference  (Create: Create new Spreadsheet | Create new Apps Script

Saturday, June 9, 2018

テキストエリア内の空行を削除したい






コード.gs
function doGet() {
  return HtmlService.createHtmlOutputFromFile("index");
}
意訳
この機能がやること
指定したHTMLファイルを表示する




index.html
<!DOCTYPE html>
<html>
  <body>
    <textarea id="ta" style="height:120px"></textarea>
    <button id="bt">空行削除</button>
    <script>
    var ta = document.getElementById("ta");
    ta.value = "\n\n一行目\n二行目\n\n\n三行目";
    var bt = document.getElementById("bt");
    bt.onclick = remove_blank_line;
    
    function remove_blank_line(){
      ta.value = ta.value.replace(/^\n/gm, "");
    }
    </script>
  </body>
</html>

意訳
 


テキストエリア
ボタン

idがtaの要素を取得
taにテキストを入れる
idがbtの要素を取得
btがクリックされたらremove_blank_lineを実行する

この機能がやること
ta内で先頭に改行がある場合はすべて複数行でも消す








Latest post

Extracting data from Google Sheets with regular expressions

Introduction Regular expressions are a powerful tool that can be used to extract data from text.  In Google Sheets, regular expressions ca...