我需要一个由其他人维护的表,并执行以下操作(以便我可以导出到csv):
这是太多的手工做,它将需要定期完成。我的javascript和google对象模型知识接近于零,但我知道这是可能的,因为我可以在VBA中这样做。我搜索了,但只能找到VBA/Excel的编程答案。
我如何在谷歌单张中有效地做到这一点?
发布于 2020-05-14 14:17:00
您可以使用breakapart()
班级来完成此操作。我假设合并的范围不是静态的,有多次出现。此脚本将解合并活动工作表中的所有合并区域。
function myFunction() {
var sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange(1, 1, sheet.getMaxRows(), sheet.getMaxColumns()).breakApart();
}
发布于 2021-03-05 11:07:48
改编自@lreeder的回答
以下内容在选定的范围内用上面的空白处打断并填充:
function onOpen() {
var ui = SpreadsheetApp.getUi();
// Or DocumentApp or FormApp.
ui.createMenu('BreakAndFill')
.addItem('Break Fill Blank Cells', 'menuItem1')
.addToUi();
}
function menuItem1() {
BreakandfillBlankWithAbove()
}
//Breaks range
//Iterates over the range from top to bottom
//and left to right, and fills blank cells
//with the value right above them.
function BreakandfillBlankWithAbove() {
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getActiveRange();
Logger.log('Range height is: ' + range.getHeight());
var values = range.getValues();
range.breakApart();
var width = values[0].length;
var height = values.length;
Logger.log('Width is ' + width);
Logger.log('Height is ' + height);
for (var i = 0; i < width; i++) {
var lastVal = '';
for(var j = 0; j < height; j++) {
var currValue = values[j][i];
var dataType = typeof(currValue);
//Empty string check returns true if dataType
//is a number, and value is zero. In that case
//we don't want to overwrite the zero, so only
//check emptyString for string types.
if(currValue === undefined ||
(dataType === 'string' && currValue == '')
) {
//getCell parameters are relative to the current range
//and ones based
var cell = range.getCell(j+1, i+1);
cell.setValue(lastVal);
}
else {
lastVal = currValue;
}
}
}
SpreadsheetApp.flush();
}
https://stackoverflow.com/questions/61798539
复制相似问题