5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

メモ:Googleシート、方眼紙化

Last updated at Posted at 2016-04-14

備忘録用

  • GoogleSpreadSheetを方眼紙っぽく(縦横の長さを同じに)するだけのスクリプト
  • 使い回しがよくわからないので備忘録として…。
hougan.gs
function onOpen(){
  var ui = SpreadsheetApp.getUi();
  
  ui.createMenu("方眼紙")
  .addItem("クイック方眼", "quickHougan")
  .addItem("数値入れて方眼", "Hougan")
  .addToUi();
}

// クイック方眼
function quickHougan(){  
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet();

  // 基準として一番上Rowの高さを取得…。
  var size = sheet.getRowHeight(1);
  
  doHougan(size,sheet);
}

// 方眼化実行
function doHougan(size){
  
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  // Rows
  for(var i=1; i<=sheet.getMaxRows(); i++){
    sheet.setRowHeight(i, size);
  }
  
  // Columns
  for(var i=1; i<=sheet.getMaxColumns(); i++){
    sheet.setColumnWidth(i, size);
  }
}

// 数値を入力して方眼
function Hougan(){
  var ui = SpreadsheetApp.getUi();

  var result = ui.prompt(
    "数値を入力して方眼化",
    "1以上の数字を入力してください(デフォルトは21):",
    ui.ButtonSet.OK_CANCEL);
  
  var button = result.getSelectedButton();
  var text = result.getResponseText();
  
  if(button == ui.Button.OK){
    var size = parseInt(text);
    if(size >= 1) {
      doHougan(size);  
    }else{  
      ui.alert("1以上の数字を入力してください。");
    }
  }  
}
5
4
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
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?