Проблемы при перемещении информации из массива на другой лист - PullRequest
0 голосов
/ 27 марта 2020

Отказ от ответственности: Новое для Javascript

Я пытаюсь создать двумерный массив и переместить его на другой лист, но не могу получить значения до go на листе. Он работает, но ничего не добавляет, и я не могу найти что-либо относительно моей проблемы.

Не берите в голову дело с переключателем или что-то еще, только первая и последняя часть моего кода - вот что мне нужно для помощи.

function infoTransfer()
{

var actveSheet = SpreadsheetApp.getActiveSpreadsheet();
var byName = actveSheet.getSheetByName("New Item Input Sheet");
var infoCols = byName.getDataRange().getNumColumns();
var infoRange = byName.getDataRange().getNumRows();

var rowData = [];
for (var a = 1; a < infoRange; a++)
{
  var colData = [];
  for (var b = 2; b < infoCols; b++)
  {
    colData.push(b);
  }
  rowData.push(colData);

  rowData[[a][b]] = byName.getRange(a + 1, b + 1, infoRange, infoCols);   
}

var itemsAddedSheet = SpreadsheetApp.openById('SheetID');
var warehouseSheet = SpreadsheetApp.openById('SheetID');
var monthValue = byName.getRange('A2').getValue();

switch (monthValue)
{
  case "January":
    var sheet = itemsAddedSheet.getSheetByName('January');
    var monthSheet = warehouseSheet.getSheetByName('January');
    var archiveSheet = warehouseSheet.getSheetByName('Archive 2020');
    break;
  case "February":
    var sheet = itemsAddedSheet.getSheetByName('February');
    var monthSheet = warehouseSheet.getSheetByName('February');
    var archiveSheet = warehouseSheet.getSheetByName('Archive 2020');
    break;
  case "March":
    var sheet = itemsAddedSheet.getSheetByName('March');
    var monthSheet = warehouseSheet.getSheetByName('March');
    var archiveSheet = warehouseSheet.getSheetByName('Archive 2020');
    break;
  case "April":
    var sheet = itemsAddedSheet.getSheetByName('April');
    var monthSheet = warehouseSheet.getSheetByName('April');
    var archiveSheet = warehouseSheet.getSheetByName('Archive 2020');
    break;
  case "May":
    var sheet = itemsAddedSheet.getSheetByName('May');
    var monthSheet = warehouseSheet.getSheetByName('May');
    var archiveSheet = warehouseSheet.getSheetByName('Archive 2020');
    break;      
  case "June":
    var sheet = itemsAddedSheet.getSheetByName('June');
    var monthSheet = warehouseSheet.getSheetByName('June');
    var archiveSheet = warehouseSheet.getSheetByName('Archive 2020');
    break;      
  case "July":
    var sheet = itemsAddedSheet.getSheetByName('July');
    var monthSheet = warehouseSheet.getSheetByName('July');
    var archiveSheet = warehouseSheet.getSheetByName('Archive 2020');
    break;      
  case "August":
    var sheet = itemsAddedSheet.getSheetByName('August');
    var sheet = warehouseSheet.getSheetByName('August');
    var archiveSheet = warehouseSheet.getSheetByName('Archive 2020');
    break;      
  case "September":
    var sheet = itemsAddedSheet.getSheetByName('September');
    var monthSheet = warehouseSheet.getSheetByName('September');
    var archiveSheet = warehouseSheet.getSheetByName('Archive 2020');
    break;     
  case "October":
    var sheet = itemsAddedSheet.getSheetByName('October');
    var monthSheet = warehouseSheet.getSheetByName('October');
    var archiveSheet = warehouseSheet.getSheetByName('Archive 2020');
    break;      
  case "November":
    var sheet = itemsAddedSheet.getSheetByName('November');
    var monthSheet = warehouseSheet.getSheetByName('November');
    var archiveSheet = warehouseSheet.getSheetByName('Archive 2020');
    break;      
  default:
    var sheet = itemsAddedSheet.getSheetByName('December');
    var monthSheet = warehouseSheet.getSheetByName('December');
   var archiveSheet = warehouseSheet.getSheetByName('Archive 2020');
    break;      
}

for (var a = 1; a < infoRange; a++)
{
  for (var b = 2; b < infoCols; b++)
  {
    colData.push(b);
  }
  rowData.push(colData);

  sheet.getRange(a + 1, b + 1, infoRange, infoCols).setValues(rowData[[a][b]].getValues());
  sheet.getRange(2, 11, infoRange - 1, 1).setValue(new Date()).setNumberFormat("mm/dd/yyyy hh:mm");
}
}

1 Ответ

0 голосов
/ 27 марта 2020

Это то, что вы ищете?

function infoTransfer() {
  const ss=SpreadsheetApp.getActive();
  const sh=ss.getSheetByName('New Item Input Sheet');
  const vs=sh.getDataRange().getValues();

  const itemsAddedSheet=SpreadsheetApp.openById('SheetID');
  const warehouseSheet=SpreadsheetApp.openById('SheetID');
  const monthValue=byName.getRange('A2').getValue();
  switch (monthValue){
    case "January":
      var sheet=itemsAddedSheet.getSheetByName('January');
      var monthSheet=warehouseSheet.getSheetByName('January');
      var archiveSheet=warehouseSheet.getSheetByName('Archive 2020');
      break;
    case "February":
      var sheet=itemsAddedSheet.getSheetByName('February');
      var monthSheet=warehouseSheet.getSheetByName('February');
      var archiveSheet=warehouseSheet.getSheetByName('Archive 2020');
      break;
    case "March":
      var sheet=itemsAddedSheet.getSheetByName('March');
      var monthSheet=warehouseSheet.getSheetByName('March');
      var archiveSheet=warehouseSheet.getSheetByName('Archive 2020');
      break;
    case "April":
      var sheet=itemsAddedSheet.getSheetByName('April');
      var monthSheet=warehouseSheet.getSheetByName('April');
      var archiveSheet=warehouseSheet.getSheetByName('Archive 2020');
      break;
    case "May":
      var sheet=itemsAddedSheet.getSheetByName('May');
      var monthSheet=warehouseSheet.getSheetByName('May');
      var archiveSheet=warehouseSheet.getSheetByName('Archive 2020');
      break;      
    case "June":
      var sheet=itemsAddedSheet.getSheetByName('June');
      var monthSheet=warehouseSheet.getSheetByName('June');
      var archiveSheet=warehouseSheet.getSheetByName('Archive 2020');
      break;      
    case "July":
      var sheet=itemsAddedSheet.getSheetByName('July');
      var monthSheet=warehouseSheet.getSheetByName('July');
      var archiveSheet=warehouseSheet.getSheetByName('Archive 2020');
      break;      
    case "August":
      var sheet=itemsAddedSheet.getSheetByName('August');
      var sheet=warehouseSheet.getSheetByName('August');
      var archiveSheet=warehouseSheet.getSheetByName('Archive 2020');
      break;      
    case "September":
      var sheet=itemsAddedSheet.getSheetByName('September');
      var monthSheet=warehouseSheet.getSheetByName('September');
      var archiveSheet=warehouseSheet.getSheetByName('Archive 2020');
      break;     
    case "October":
      var sheet=itemsAddedSheet.getSheetByName('October');
      var monthSheet=warehouseSheet.getSheetByName('October');
      var archiveSheet=warehouseSheet.getSheetByName('Archive 2020');
      break;      
    case "November":
      var sheet=itemsAddedSheet.getSheetByName('November');
      var monthSheet=warehouseSheet.getSheetByName('November');
      var archiveSheet=warehouseSheet.getSheetByName('Archive 2020');
      break;      
    default:
      var sheet=itemsAddedSheet.getSheetByName('December');
      var monthSheet=warehouseSheet.getSheetByName('December');
      var archiveSheet=warehouseSheet.getSheetByName('Archive 2020');
      break;      
  }
  sheet.getRange(1,1,vs.length,vs[0].length).setValues(vs);
  sheet.getRange(2, 11, sheet.getLastRow()-1, 1).setValue(new Date()).setNumberFormat("mm/dd/yyyy hh:mm");
  }
}

Непонятно, что вы будете sh делать с monthSheet и archiveSheet.

Возможно, я бы подумал сделать это следующим образом:

function infoTransfer() {
  const ss=SpreadsheetApp.getActive();
  const sh=ss.getSheetByName('New Item Input Sheet');
  const vs=sh.getDataRange().getValues();
  const itemsAddedSheet=SpreadsheetApp.openById('SheetID');
  const warehouseSheet=SpreadsheetApp.openById('SheetID');
  const monthValue=byName.getRange('A2').getValue();
  const sheet=itemsAddedSheet.getSheetByName(monthValue);
  const monthSheet=warehouseSheet.getSheetByName(monthValue);
  const archiveSheet=warehouseSheet.getSheetByName('Archive 2020');
  sheet.getRange(1,1,vs.length,vs[0].length).setValues(vs);
  sheet.getRange(2, 11, sheet.getLastRow()-1, 1).setValue(new Date()).setNumberFormat("mm/dd/yyyy hh:mm");
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...