Trong ví dụ này chúng ta sẽ sử dụng một số kiến thức về html, google sheet, apps script để lấy dữ liệu từ Cell Spreadsheet và hiển thị giá trị đó lên trình duyệt web (Browser).
Các bài excel thực hành ứng dụng khác:
- Web App Script CSS JS | Tạo hiệu ứng Click button Nổ tung các mảnh giấy và chuyển link
- Web App Script CSS | Tạo button Liên hệ gồm 3 option đẹp mắt cho trang web
- Web App Script Webapp | Hiệu ứng hoa rơi – Form nhập liệu Gửi nội dung đến email
- Web App Script | Thanh trạng thái Status bar – Giá trị thể hiện theo điểm và label.
- Google sheet Apps script | Data Entry Form – Tự động đọc số tiền thành chữ ở trường input
- Google sheet Apps script | Cập nhật điểm lớp học – Theo danh sách lớp và Theo từng học sinh
- Google sheet, apps script Định dạng dấu phân cách hàng ngàn cho input
- Google sheet apps script | Chọn năm và kiểu biểu đồ để Load dữ liệu lên website
- Google sheet apps script | Scan QR code – Filter and get data table display on webapp
- Google sheet apps script Filter to get data to display on webapp, fill background color for data row
Mã trong file Code.gs
function doGet(e){
return HtmlService.createHtmlOutputFromFile("index.html");
}
function getDatacell() {
var sw=SpreadsheetApp.getActiveSpreadsheet();
var ss=sw.getActiveSheet();
let dataCell = ss.getRange("C3").getValue();
let display="<span>" +dataCell+ "</span>";
return display;
}
Mã trong file index.html
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<title>Lấy dữ liệu từ Cell của Spreadsheet, hiển thị lên Browser</title>
</head>
<body >
<table align="center">
<tr>
<td style="color: blue; font-size:3em; font-weight:bold;">Tổng số lượng: </td>
<td style="text-align:c enter; color: red; font-size:3em; font-weight:bold;" id="result">ds</td>
</tr>
</table>
<script>
let loading = "Đang lấy dữ liệu...";
document.querySelector('#result').innerHTML=loading;
function onSuccess(response){
let result = "<span>"+response+"</span>";
document.querySelector('#result').innerHTML=result;
}
google.script.run.withSuccessHandler(onSuccess)
.getDatacell();
</script>
</body>
</html>