i'm making an index that generates automatically from a Google Spreadsheet.
My script reads two columns, one with names and the other one with links. Then it generates an HTML with all the names as <li><a>"The name"</a></li>
.
My idea is to pass the links on the spreadsheet to the href=" "
on each name, but I don't know how to do it.
Here is my .gs and .html code, and a link to my spreadsheet (to work on it, you may have to make a copy).
https://docs.google.com/spreadsheets/d/1fEYqPnp9SIS7I2lzeeoEP7Pui4l0dgLD6t7D9Lki9oE/edit?usp=sharing
GS code
function doGet() {
return HtmlService.createHtmlOutputFromFile('index');
}
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Index');
function readData() {
var range = spreadsheet.getRange(1, 1,spreadsheet.getLastRow(), spreadsheet.getLastColumn()).getValues();
Logger.log(range);
return range;
};
function readLinks() {
var links = spreadsheet.getRange(1, 2,spreadsheet.getLastRow(), spreadsheet.getLastColumn()).getValues();
Logger.log(links);
return links;
};
HTML code
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<div>
<ul>
<li id="proced"><a id="link"></a></li>
</ul>
</div>
<script>
function getData(values) {
values.forEach(function(item, index) {
var x = document.getElementById("link");
x.innerHTML += '<li><a href="">' + item[0] + '</li></a>';
});
}
google.script.run.withSuccessHandler(getData).readData();
</script>
</body>
</html>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…