问题
I have google sheet with a cell containing html code. I would like to know the best way to show this html in a webpage. I have tried with google spreadsheets API and google visualization API...
回答1:
Using Google Apps Script, this can be as simple as:
function doGet() {
var spreadsheet = SpreadsheetApp.openById("0Aq4s9w_HxMs7dFVuQ0hDaWl1VVZsQ1RBTVZqM0dHLXc"); // replace with your sheet id
var html = spreadsheet.getRange("A1").getValue(); // My html is in cell A1
return HtmlService.createHtmlOutput(html);
}
Check out the Apps Script documentation Getting Started and Tutorial sections to get an idea of how to develop with Apps Script.
回答2:
Here is how you can display information from a single cell using the Javascript charts API. Better ways may be available, I am not an expert. To get the snippet below working just add your spreadsheet url and set the range.
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
// https://google,developers.appspot.com/chart/interactive/docs/spreadsheets#gid
google.load('visualization', '1', {packages: ['corechart', 'line']});
google.setOnLoadCallback(drawChart);
function drawChart() {
// Add your sheets url and range below
var spreadsheetUrl = "https://your sheets url here?range=A1";
var query = new google.visualization.Query(spreadsheetUrl);
query.send(handleQueryResponse);
}
function handleQueryResponse(response) {
var dataTable = response.getDataTable();
// https://developers.google.com/chart/interactive/docs/reference?hl=en#methods
// getValue(rowIndex, columnIndex)
document.getElementById("test").innerHTML = dataTable.getValue(0, 0);
}
</script>
</head>
<body>
<p id="test"></p>
</body>
</html>
来源:https://stackoverflow.com/questions/13699589/display-the-content-of-a-google-sheet-cell-in-a-web-page