Created
October 15, 2020 03:12
-
-
Save ttsukagoshi/bfd7057b717a5b9321329a3c138ecbc7 to your computer and use it in GitHub Desktop.
Gets the cells' height and width in pixels for the selected range in Google Spreadsheet in form of a 2-d JavaScript array; the array values are ordered in the same way as executing Range.getValues()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Gets the cells' height and width in pixels for the selected range in Google Spreadsheet in form of a 2-d JavaScript array; | |
* the array values are ordered in the same way as executing Range.getValues() | |
* @param {Object} activeSheet The active Sheet class object in Google Spreadsheet, e.g., SpreadsheetApp.getActiveSheet() | |
* @param {Object} activeRange The selected Range class object in Google Spreadsheet, e.g., SpreadsheetApp.getActiveRange() | |
*/ | |
function cellPixSizes(activeSheet, activeRange) { | |
var rangeStartCell = { 'row': activeRange.getRow(), 'column': activeRange.getColumn() }; | |
var cellValues = activeRange.getValues(); | |
var cellPixSizes = cellValues.map(function(row, rowIndex) { | |
let rowPix = activeSheet.getRowHeight(rangeStartCell.row + rowIndex); | |
let rowPixSizes = row.map(function(column, colIndex) { | |
let cellSize = {'height': rowPix, 'width': activeSheet.getColumnWidth(rangeStartCell.column + colIndex)}; | |
return cellSize; | |
}); | |
return rowPixSizes; | |
}); | |
return cellPixSizes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment