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:
- VBA Excel Xây dựng hàm chuyển chuỗi có dấu thành không dấu, khoản trắng thành dấu –
- Google sheet Webapp | Lấy dữ liệu trên Sheet hiển thị dạng Bảng có phân trang trùy chọn trên website
- Web App Script | Trang trắc nghiệm online hỗ trợ hình ảnh, lưu file kết quả – Form nhập bộ câu hỏi
- Google sheet Webapp Quản lý Lịch dạy học giáo viên trong trung tâm-Lọc theo Tên-Lớp-Khung giờ -Môn
- Google sheet webapp | CRUD FORM – ĐIỀN THÔNG TIN TỪ FORM VÀO TEMPLATE GOOGLE DOC, KÈM HÌNH ẢNH 1
- Google sheet webapp | Dropdown phụ thuộc – Truy xuất Spreadsheet và các Sheet phụ thuộc từ Folder
- Tạo hóa đơn trên Google sheet – Gửi email đính kèm hóa đơn pdf – Quản lý url hóa đơn trên danh sách
- Google sheet Ứng dụng theo dõi đơn hàng – Danh sách sản phẩm mua, trạng thái đơn hàng
- Tip on Ms Word Hướng dẫn tạo ngắt trang, xóa ngắt trang đơn lẽ hoặc toàn bộ ngắt trang trên file doc
- Google sheet | Generate QR Codes – Mã hóa nội dung Cell – Thêm hình ở giữa mã QR code
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>