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:
- Date
- ID
- Local
- Tipo
- Modelo
- Notas
- Lote
- Custo
- Preço
- Estado
The weird names are just because i'm brazilian.
(First time asking a question here)