I am struggling to get the values from an HTML table and paste it to a Google Sheet via SetValues.
- With the click of a button an HTML popup appears.
- In that popup there's an HTML table where the user will make some inputs
- When they click on "btn" button it triggers the function pasteBrief() within the script section in HTML
- This function then triggers a Google Script pasteBriefVal(tableval) on the GS Server side and sends the values to a specific range.
- The issue: I know the values are pushed into the array, but I suspect they don't get properly structured so the setValues can paste it accordingly.
HTML: table
<div>
<img src="https://i.ibb.co/LZ1S1ZD/plus-sign.png" onclick="newRows()" width="25px" height="auto"></img>
<img src="https://i.ibb.co/GP6GKdn/minus-sign.png" onclick="newRowssss()" width="25px" height="auto"></img>
<button id="btn" onclick="pasteBrief()" style="color: #63d297;">Generate Brief</button>
<table id="brief_table">
<thead>
<tr>
<th>Content category</th>
<th>Description</th>
<th>Content type</th>
<th>Format</th>
<th>Channel</th>
<th>Assets</th>
<th>Start date</th>
<th>End date</th>
<th>Relevant links</th>
<th>Comments</th>
</tr>
</thead>
<tbody>
<tr>
<td contenteditable='true'></td>
<td contenteditable='true'>Test</td>
<td contenteditable='true'></td>
<td contenteditable='true'></td>
<td contenteditable='true'></td>
<td contenteditable='true'>Test</td>
<td contenteditable='true'>Test</td>
<td contenteditable='true'>Test</td>
<td contenteditable='true'>Test</td>
<td contenteditable='true'>Test</td>
</tr>
</tbody>
</table>
</div>
<script>
function pasteBrief() {
var table = document.getElementById("brief_table");
var tablevalues = [];
var tablevaluesr = []; // do I need to arrays instead of one???
var tablevaluesc = []; // just playing with different combination of these as I'm unsure how to make it work
for (var r = 0, n = table.rows.length; r < n; r++) {
for (var c = 0, m = table.rows[r].cells.length; c < m; c++) {
tablevalues.push([table.rows[r].cells[c].innerHTML]);
}
}
google.script.run.pasteBriefVal(tablevalues);
}
</script>
GS paste values onto Spreadsheet
function pasteBriefVal(tableval){ SpreadsheetApp.getActive().getSheetByName('Sheet1').getRange('b1:u').setValues(tableval);
}