取消合并电子表格单元格,并用数据填充合并前的空白单元格 [英] Unmerge spreadsheet cells and fill ex-merged empty cells with data

查看:54
本文介绍了取消合并电子表格单元格,并用数据填充合并前的空白单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

breakApart()正常,但我d想用合并单元格的数据填充空白单元格.

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();

推荐答案

如果您已经有了该值,则可以在整个范围内 setValue()所需的值,并且将填充所有范围具有相同的值.

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()已经仅返回左上角单元格中的值.因此上述链接有效.

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

这篇关于取消合并电子表格单元格,并用数据填充合并前的空白单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆