HTML Apps script Lấy dữ liệu từ CELL Spreadsheet lên Browser
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:
- Google Apps script, html Tạo form tìm kiếm kết quả học tập sinh viên đơn giản
- Gộp nhiều file PDF thành 1 file
- HTML Apps script Lấy dữ liệu từ CELL Spreadsheet lên Browser
- Tạo và lập trình Checkbox trên Google sheet
- Tránh bị đảo lộn Ngày-Tháng trên Google sheet
- Google Apps script Tạo menu trên Spreadsheet
- Google Apps scrip Tạo form nhập liệu – Hình ảnh, thêm mới, tìm kiếm, cập nhật, xóa
- Google sheet Lập danh sách tên các file trong folder lên sheet của spreadsheet
- VBA EXCEL Tạo UserForm tìm kiếm theo chuyên mục, kết quả được hiển thị ở Listbox trên form
- Hiệu ứng biến hình nhiều đối tượng trên powerpoint
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>