// 使用法: // このファイルを Sheet.cms という名前で Cassava Editor の Macro/lib フォルダに置いてください。 // // SpreadsheetApp.getActiveSheet() で、Sheet オブジェクトを取得できます。 // Sheet クラスは、Google Apps Script の Sheet クラスの一部のメソッドを実装しています。 // https://developers.google.com/apps-script/reference/spreadsheet/sheet import { Range, getActiveRange, getCurrentCell, getDataRange } from "lib/Range.cms"; class Sheet { appendRow(rowContents) { y = Bottom + 1; for (i = 0; i < rowContents.length; i++) { [i+1,y] = rowContents[i]; } return this; } autoResizeColumn(columnPosition) { AdjustColWidth(columnPosition); return this; } autoResizeColumns(startColumn, numColumns) { for (x = startColumn; x < startColumn + numColumns; x++) { AdjustColWidth(x); } return this; } autoResizeRows(startRow, numRows) { for (y = startRow; y < startRow + numRows; y++) { AdjustRowHeight(y); } return this; } clear() { UnFix(); Right = 1; Bottom = 1; Col = 1; Row = 1; [1,1] = ""; return this; } clearContents() { return this.clear(); } deleteColumn(columnPosition) { DeleteCol(columnPosition); return this; } deleteColumns(columnPosition, howMany) { DeleteCol(columnPosition, columnPosition + howMany - 1); } deleteRow(rowPosition) { DeleteRow(rowPosition); return this; } deleteRows(rowPosition, howMany) { DeleteRow(rowPosition, rowPosition + howMany - 1); } getActiveRange() { return getActiveRange(); } getActiveSheet() { return this; } getColumnWidth(columnPosition) { return GetColWidth(columnPosition); } getCurrentCell() { return getCurrentCell(); } getDataRange() { return getDataRange(); } getFrozenColumns() { return Left - 1; } getFrozenRows() { return Top - 1; } getLastColumn() { return Right; } getLastRow() { return Bottom; } getRange(row, column, ...numbers) { if (numbers.length >= 2) { return new Range(row, column, numbers[0], numbers[1]); } else if (numbers.length == 1) { return new Range(row, column, numbers[0], 1); } else { return new Range(row, column, 1, 1); } } getRowHeight(rowPosition) { return GetRowHeight(rowPosition); } getSheetValues(startRow, startColumn, numRows, numColumns) { return new Range(startRow, startColumn, numRows, numColumns).getValues(); } insertColumnAfter(afterPosition) { InsertCol(afterPosition + 1); return this; } insertColumnBefore(beforePosition) { InsertCol(beforePosition); return this; } insertColumns(columnIndex, numColumns) { InsertCol(columnIndex, columnIndex + numColumns - 1); } insertColumnsAfter(afterPosition, howMany) { InsertCol(afterPosition + 1, afterPosition + howMany); return this; } insertColumnsBefore(beforePosition, howMany) { InsertCol(beforePosition, beforePosition + howMany - 1); return this; } insertRowAfter(afterPosition) { InsertRow(afterPosition + 1); return this; } insertRowBefore(beforePosition) { InsertRow(beforePosition); return this; } insertRows(rowIndex, numRows) { InsertRow(rowIndex, rowIndex + numRows - 1); } insertRowsAfter(afterPosition, howMany) { InsertRow(afterPosition + 1, afterPosition + howMany); return this; } insertRowsBefore(beforePosition, howMany) { InsertRow(beforePosition, beforePosition + howMany - 1); return this; } moveColumns(columnSpec, destinationIndex) { if (columnSpec.startColumn < destinationIndex) { for (i = columnSpec.numColumns - 1; i >= 0; i--) { MoveCol(columnSpec.startColumn + i, destinationIndex + i); } } else if (columnSpec.startColumn > destinationIndex) { for (i = 0; i < columnSpec.numColumns; i++) { MoveCol(columnSpec.startColumn + i, destinationIndex + i); } } } moveRows(rowSpec, destinationIndex) { if (rowSpec.startRow < destinationIndex) { for (i = rowSpec.numRows - 1; i >= 0; i--) { MoveRow(rowSpec.startRow + i, destinationIndex + i); } } else if (rowSpec.startRow > destinationIndex) { for (i = 0; i < rowSpec.numRows; i++) { MoveRow(rowSpec.startRow + i, destinationIndex + i); } } } setActiveRange(range) { return range.activate(); } setColumnWidth(columnPosition, width) { SetColWidth(columnPosition, width); return this; } setColumnWidths(startColumn, numColumns, width) { for (i = 0; i < numColumns; i++) { SetColWidth(startColumn + i, width); } return this; } setCurrentCell(cell) { return cell.activateAsCurrentCell(); } setFrozenColumns(columns) { Row = Top; UnFix(); Col = columns + 1; FixUpLeft(); } setFrozenRows(rows) { Col = Left; UnFix(); Row = rows + 1; FixUpLeft(); } setRowHeight(rowPosition, height) { SetRowHeight(rowPosition, height); return this; } setRowHeights(startRow, numRows, height) { for (i = 0; i < numRows; i++) { SetRowHeight(startRow + i, height); } return this; } sort(columnPosition, ...ascending) { descending = ascending.length > 0 && !ascending[0]; Sort(1, Top, Right, Bottom, columnPosition, descending, true, true, true); } }