// AdjustCells.cms 作成者:いっち 2023年01月04日(水) // // 使用法: // Cassava Editor の組み込み関数 AdjustColWidth と AdjustRowHeight を基にして、「飛び飛びの指定」と「範囲指定」を行えるようにします。 // Cassava Editor の対応バージョンは、Ver.2.5 β1 ~ です。 // // このファイルを AdjustCells.cms という名前で Cassava Editor の Macro/lib フォルダに置いてください。 // // 下記のいずれかの形で、import します。(必要なものを、選んでください。) // import { AdjustColWidths } from "lib/AdjustCells.cms"; // import { AdjustRowHeights } from "lib/AdjustCells.cms"; // import { AdjustColWidths, AdjustRowHeights } from "lib/AdjustCells.cms"; // // ※import せずに利用する場合は、Cassava Editor ヘルプ「マクロ~インポート」のところをご参照ください。 // // 1) 飛び飛びの列(たとえば、1列目,3列目,5列目)を、AdjustColWidth したい場合は、 // AdjustColWidths(1,3,5); とします。 // // 2) 飛び飛びの行(たとえば、1行目,3行目,5行目)を、AdjustRowHeight したい場合は、 // AdjustRowHeights(1,3,5); とします。 // // 3) 範囲指定をする場合は、下記のように指定します。 // 3-1) 10列目から12列目を指定する場合 // AdjustColWidths("10-12"); // 3-2) 10行目から12行目を指定する場合 // AdjustRowHeights("10-12"); // // 4) 「飛び飛びの指定」と「範囲指定」を合わせて指定する事も出来ます。 // 4-1) 上記の 1) と 3-1) を合わせる場合 // AdjustColWidths(1,3,5,"10-12"); // 4-2) 上記の 2) と 3-2) を合わせる場合 // AdjustRowHeights(1,3,5,"10-12"); // // 5) SelLeft, SelRight, SelTop, SelBottom を利用する場合は、下記のように指定します。 // 5-1) SelLeft と SelRight の場合 // AdjustColWidths(SelLeft+"-"+SelRight); // 5-2) SelTop と SelBottom の場合 // AdjustRowHeights(SelTop+"-"+SelBottom); // // 作成動機: // 「他のマクロから利用可能なライブラリ」の「SpreadsheetApp.zip」の「Sheet.cms」には、autoResizeColumns, autoResizeRows があります。 // それらと範囲の指定方法は異なりますが、ここに書いた AdjustColWidths, AdjustRowHeights もあっていいかなと思い、作成しました。 function AdjustColFrom(from) { for (xn = 0; xn < from.length; xn++) { if (from[xn].search(/^\d+$/)==0) { AdjustColWidth(int(from[xn])); } else if (from[xn].search(/^(\d+)(?: +)*-(?: +)*(\d+)$/)==0) { num1 = int(from[xn].replace(/^(\d+)(?: +)*-(?: +)*(\d+)$/, "$1")); num2 = int(from[xn].replace(/^(\d+)(?: +)*-(?: +)*(\d+)$/, "$2")); min_num = min(num1,num2); max_num = max(num1,num2); for (s_xn = min_num; s_xn <= max_num; s_xn++) { AdjustColWidth(s_xn); } } } } function AdjustRowFrom(from) { for (yn = 0; yn < from.length; yn++) { if (from[yn].search(/^\d+$/)==0) { AdjustRowHeight(int(from[yn])); } else if (from[yn].search(/^(\d+)(?: +)*-(?: +)*(\d+)$/)==0) { num1 = int(from[yn].replace(/^(\d+)(?: +)*-(?: +)*(\d+)$/, "$1")); num2 = int(from[yn].replace(/^(\d+)(?: +)*-(?: +)*(\d+)$/, "$2")); min_num = min(num1,num2); max_num = max(num1,num2); for (s_yn = min_num; s_yn <= max_num; s_yn++) { AdjustRowHeight(s_yn); } } } } function AdjustColWidths(...args) { return AdjustColFrom(args); } function AdjustRowHeights(...args) { return AdjustRowFrom(args); }