附加其他选项卡中的行而不会丢失格式

时间:2018-10-10 08:43:05

标签: google-apps-script google-sheets google-sheets-macros

为了整理一组银行帐户和信用卡对帐单,我下载了它们。然后,我在Excel或Google表格中打开它们,将它们重新组织到匹配的列中,将它们全部放在一个标签中(总计),然后进行排序。

现在的问题是我如何从单张纸上复印。我认为在粘贴并重复(手动方式)通过搜索找到的某些功能后,我已经很接近了。问题在于此功能会删除源行中的所有格式

Example sheet

最后一个选项卡example_TOTAL放在那里只是为了显示我希望选项卡TOTAL在完成该过程后如何显示。

到目前为止,这是我执行最多的功能,但是会清除格式设置(颜色)。

function Copy() {
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); 
  var ss = spreadsheet.getSheetByName('TabA'); //replace with source Sheet tab name
  var range = ss.getRange('A1:L'); //assign the range you want to copy
  var data = range.getValues();
  var ts = spreadsheet.getSheetByName('TOTAL'); //replace with destination Sheet tab name
  ts.getRange(ts.getLastRow()+1, 1, data.length, data[0].length).setValues(data);

  var ss = spreadsheet.getSheetByName('TabB'); //replace with source Sheet tab name
  var range = ss.getRange('A1:L'); //assign the range you want to copy
  var data = range.getValues();
  ts.getRange(ts.getLastRow()+1, 1, data.length, data[0].length).setValues(data);

  var ss = spreadsheet.getSheetByName('TabC'); //replace with source Sheet tab name
  var range = ss.getRange('A1:L'); //assign the range you want to copy
  var data = range.getValues();
  ts.getRange(ts.getLastRow()+1, 1, data.length, data[0].length).setValues(data);

  var ss = spreadsheet.getSheetByName('TabD'); //replace with source Sheet tab name
  var range = ss.getRange('A1:L'); //assign the range you want to copy
  var data = range.getValues();
  ts.getRange(ts.getLastRow()+1, 1, data.length, data[0].length).setValues(data);
}

function copyFromTo(){

  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();

  var ss = spreadsheet.getSheetByName('TabA');
  var copy = ss.getRange('A1:L');

  var target = spreadsheet.getSheetByName('TOTAL');
  var dest = target.getRange('A1:L');

  copy.copyTo(dest);
  var ss = spreadsheet.getSheetByName('TabB');
  var copy = ss.getRange('A1:L');
  copy.copyTo(dest);
  var ss = spreadsheet.getSheetByName('TabC');
  var copy = ss.getRange('A1:L');
  copy.copyTo(dest);
  var ss = spreadsheet.getSheetByName('TabD');
  var copy = ss.getRange('A1:L');
  copy.copyTo(dest);

}

如何从这些工作表中追加内容并保持格式不变?

0 个答案:

没有答案