Unmerge spreadsheet cells and fill ex-merged empty cells with data

﹥>﹥吖頭↗ 提交于 2021-01-01 06:25:47

问题


breakApart() works fine, but I'd like to fill the empty cells with merged cell's data.

var sheet = SpreadsheetApp.getActiveSheet();
var sheetRange = sheet.getRange(1, 1, sheet.getMaxRows(), sheet.getMaxColumns()); 
sheetRange.breakApart();  

I got the value I need, but how can I get the cells to fill?

var value = (cell.isPartOfMerge() ? cell.getMergedRanges()[0].getCell(1,1) : cell).getValue();

回答1:


If you already have the value, You can setValue() the desired value over the entire range and all the range will be filled with the same value.

const sheet = SpreadsheetApp.getActiveSheet();
const sheetRange = sheet.getDataRange(); 
sheetRange
  .getMergedRanges()
  .forEach(range => range.setValue(range.breakApart().getValue()));

getValue() already returns only the value in the top left cell. So the above chaining works.



来源:https://stackoverflow.com/questions/64395621/unmerge-spreadsheet-cells-and-fill-ex-merged-empty-cells-with-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!