Created
November 19, 2021 06:15
-
-
Save johnpaulada/7a852d7724e2942ad00ca1431b38a6a1 to your computer and use it in GitHub Desktop.
Google Sheets Script for Merging Each Row
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
| function mergeHorizontalAll(numOfRows, numOfColumns) { | |
| const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet() | |
| const rowIds = [...Array(numOfRows).keys()] | |
| rowIds.forEach(rowId => { | |
| console.log(rowId) | |
| const range = sheet.getRange(rowId + 1, 1, 1, numOfColumns) | |
| const value = range.getValues()[0].join(", ") | |
| range.merge() | |
| range.setValue(value) | |
| range.setHorizontalAlignment('center') | |
| }) | |
| } | |
| const numberOfRows = 100 | |
| const numberOfColumns = 3 | |
| mergeHorizontalAll(numberOfRows, numberOfColumns) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment