0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

スプシでもエクセルみたいに半角数字にしてほしい

Posted at

スプシの細かい不満:全角数字

Officeスイートのオルタナティブとして、GoogleWorkSpaceを長らく使っていますが、細かいところではスプシがエクセルに劣るところもあります。特に全角数字を入れたあとの挙動が、エクセルであれば「表計算で全角数字なんてありえないっしょ!」と半角に変換してくれますが、スプシではそんな変換してくれません。地味にストレスです。

解決策:強制的に変換するGASを組み込む

このGASを組み込みます

function onEdit(e) {
  let range = e.range;
  let value = range.getValue();

  let convertedValue = value.replace(/[0-9,/]/g, function(s) {
    switch(s) {
      case '': return ',';
      case '': return '/';
      default: return String.fromCharCode(s.charCodeAt(0) - 0xFEE0);
    }
  });
  
  if (value !== convertedValue) {
    range.setValue(convertedValue);
  }
}

これで編集が終わると、全角数字が半角に変換されます。

より機能を追加するには

  • 本当であればセルの書式をみて、全角が入らなさそうなところだけやればいい
  • だけどその処理が微妙に重い
  • そもそもGASのレスポンスが悪い
  • これ以上余計な処理を加えたくない

ということで、一旦ここで打ち止め

結論

地味にエクセルが手放せない

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?