Pregunta

Estoy tratando de escribir un guión sencillo para una hoja de cálculo de Google Docs. Los dos enlaces siguientes son una captura de pantalla de las hojas que estoy escribiendo el guión de.

Todavía estoy aprendiendo a escribir JavaScript, pero esto es lo que estoy tratando de hacer. Espero que esto tenga sentido. ¿Puede alguien ayudarme con esto?

get.sheetbyname "Purchase Orders"
    If column E  == "stock"
    var qty == three cells left of cell e
    var partNum == two cells left of cell e

get.sheetbyname "Parts inventory"
    loop through column C until you find partNum
    var oldQty == number(two cells left of partNum)
    add qty to oldQty to get new qty

¿Fue útil?

Solución

You'll definitely need to get familiar with JavaScript quickly. It's a powerful language and seems easy to pick up but has many differences from other popular, seemingly related languages (e.g. Java, C, etc). Once you're comfortable with JavaScript, you'll want to familiarize yourself with the Google Apps Script Spreadsheet Services APIs. These APIs allow you to script Google Docs spreadsheets like you would other spreadsheet applications, such as Microsoft Excel. Start by opening your workbook and browsing to "Tools > Scripts > Script Editor...", then creating a new named script.

Here's a start at what you're trying to do specifically. It looks like you're trying to find out how many purchase orders exist for some item and update the quantity in the inventory sheet.

function updateInventoryFromPurchaseOrders() {
  var purchaseOrders = {}; // A mapping of partNumber => quantity.
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName('Purchase Orders');
  if (sheet) {
    // For each row, if column "E" == "stock" then set partNumber, quantity.
    purchaseOrders[partNumber] = quantity;
  }
  // Now purchaseOrders should look like {'SL249':5, 'ML50':1, 'MWF':1}

  sheet = ss.getSheetByName('Inventory');
  if (sheet) {
    // For each row, set quantity, partNumber.
    var purchased = purchaseOrders[partNumber];
    // Set column "A" value = quantity + purchased
  }
}

Reading and writing the values from individual cells will require you to use Ranges, the docs linked above should give you enough examples to get you the rest of the way.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top