Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88030

How can I make a unique ID generator on Office.JS

$
0
0

I'm trying to use Office.JS to insert some rows into a table, there's more to it but i'll try to keep it simple.

The idea is to type details about a product on various inputs and then submit it to the table creating a full row with everything i've written.

The problem is that i don't know how can i make unique IDs on Office.JS, i thought about getting the last ID on the table then just do something like:

ID = lastID + 1

But i don't know how to get the value from the last ID on the table (the documentation it's just incredibly hard for me to understand)

This is what i did so far:

function run() {
  return Excel.run(function(context) {
    var sheet = context.workbook.worksheets.getItem('Principal');
    var mainTable = sheet.tables.getItem("Main");

    var local = $('#local').val();
    var tipo = $('#tipo').val();
    var modelo = $('#modelo').val();
    var notas = $('#notas').val();
    var lote = $('#lote').val();
    var custo = $('#custo').val();
    var preco = $('#preco').val();
    var estado = $('#estado').val();

    var produto = [data, id, local, tipo, modelo, notas, lote, custo, preco, estado];

    var id = ""

    mainTable.rows.add(null, [produto]);

    return context.sync().then(function() {
      console.log(produto);
    });
  });
}

Every column that i have in it's sequence:

  1. Date
  2. ID
  3. Local
  4. Tipo
  5. Modelo
  6. Notas
  7. Lote
  8. Custo
  9. Preço
  10. Estado

The weird names are just because i'm brazilian.

(First time asking a question here)


Viewing all articles
Browse latest Browse all 88030

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>