英文:
How to change text to link in google web app?
问题
这是您提供的代码的翻译部分:
所以我有一个包含我们项目中使用的所有电子表格的列表。
电子表格中的简单表格,带有指向其他电子表格的链接。我想将它变成一个网站,所以我编写了一个简单的代码并部署了它。我遇到的问题是网站上的链接只是普通文本,那么我该如何将它们变成链接?
你有任何想法如何解决这个问题吗?
GAS(Google Apps Script)代码:
function doGet() {
return HtmlService.createTemplateFromFile('Index').evaluate();
}
function getData(){
const ss = SpreadsheetApp.openByUrl('**********************');
const srcSheet = ss.getSheetByName("Sheet1");
const srcValues = srcSheet.getRange(2, 1, srcSheet.getLastRow()-1, 4).getDisplayValues();
return srcValues;
}
function include(filename) {
return HtmlService.createHtmlOutputFromFile(filename).getContent();
}
HTML代码:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script src="https://cdn.datatables.net/1.10.23/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.23/js/dataTables.bootstrap4.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.2/css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.23/css/dataTables.bootstrap4.min.css">
<script>
google.script.run.withSuccessHandler(showData).getData();
function showData(dataArray){
$(document).ready(function(){
$('#data-table').DataTable({
data: dataArray,
columns: [
{"title":"文件"},
{"title":"内容"},
{"title":"链接"},
{"title":"联系方式"}
]
});
});
}
</script>
</head>
<body>
<!--- 表格---->
<div class="container center">
<br>
<div class="row center">
<table id="data-table" class="table table-striped table-sm table-hover table-bordered">
<!-- 表格数据由上面的 showData() JavaScript 函数添加 -->
</table>
</div>
</div>
</body>
</html>
希望这能帮助您理解代码的内容。如果您有其他问题,请随时提出。
英文:
So I have spreadsheet with list of all spreadsheets we use for the project.
Simple table in spreadsheet with links to other spreadsheet. I wanted to have it as a website so I create a simple code and deployed. The problem I have is that links are regular text on the website so how could I change them to links?
do you have any ideas how it could be solved?
GAS:
function doGet() {
return HtmlService.createTemplateFromFile('Index').evaluate();
}
function getData(){
const ss = SpreadsheetApp.openByUrl('**********************');
const srcSheet = ss.getSheetByName("Sheet1");
const srcValues = srcSheet.getRange(2, 1, srcSheet.getLastRow()-1, 4).getDisplayValues()
return srcValues;
}
function include(filename) {
return HtmlService.createHtmlOutputFromFile(filename)
.getContent();
}
HTML:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script src="https://cdn.datatables.net/1.10.23/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.23/js/dataTables.bootstrap4.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.2/css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.23/css/dataTables.bootstrap4.min.css">
<script>
google.script.run.withSuccessHandler(showData).getData();
function showData(dataArray){
$(document).ready(function(){
$('#data-table').DataTable({
data: dataArray,
columns: [
{"title":"File"},
{"title":"Content"},
{"title":"Link"},
{"title":"Contact"}
]
});
});
}
</script>
</head>
<body>
<!--- TABLE---->
<div class="container center">
<br>
<div class="row center">
<table id="data-table" class="table table-striped table-sm table-hover table-bordered">
<!-- TABLE DATA IS ADDED BY THE showData() JAVASCRIPT FUNCTION ABOVE -->
</table>
</div>
</div>
</body>
</html>
答案1
得分: 2
在你的脚本中,如何使用render
?在这种情况下,请按照以下方式修改你的JavaScript。
从:
columns: [
{"title":"File"},
{"title":"Content"},
{"title":"Link"},
{"title":"Contact"}
]
到:
columns: [
{"title":"File"},
{"title":"Content"},
{"title":"Link", "render": e => `<a href="${e}" target="_blank">${e}</a>`},
{"title":"Contact"}
]
- 根据你的脚本,我猜测列"C"是超链接。
参考链接:
英文:
In your script, how about using render
? In this case, please modify your Javascript as follows.
From:
columns: [
{"title":"File"},
{"title":"Content"},
{"title":"Link"},
{"title":"Contact"}
]
To:
columns: [
{"title":"File"},
{"title":"Content"},
{"title":"Link", "render": e => `<a href="${e}" target="_blank">${e}</a>`},
{"title":"Contact"}
]
- From your script, I guessed that the column "C" is the hyperlink.
Reference:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论