Google Apps script, html Tạo form tìm kiếm kết quả học tập sinh viên đơn giản
Giaoan.link chia sẻ đến các bạn project Google Apps script, html Tạo form tìm kiếm kết quả học tập sinh viên đơn giản. Trong ví dụ này mình sử dụng dịch vụ đám mây google sheet và kết hợp với html cũng như mã apps script để tạo một tiện ích tìm kiếm kết quả của sinh viên trên môi trường mạng rất dễ dàng. Các bạn có thể sử dụng ví dụ này để tùy biến theo nhiều mục đích khác nhau.
Các bài tập excel ứ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ã trên file Code.gs
function doGet(e){
return HtmlService.createHtmlOutputFromFile('Index.html')
}
function submitData(obj){
var ws=SpreadsheetApp.openById("1ISHx-xbXxu2b2Az-R8xM22XYR_UNrjTY4rBTFVY8pfs");
var ss=ws.getSheetByName("Data");
var flag = 1;
var lr=ss.getLastRow();
for(var i=2;i<=lr;i++){
var vId=ss.getRange(i,1).getValue();
if(vId==obj){
flag=0;
let b1= ss.getRange(i,2).getValue();
let b2= ss.getRange(i,3).getValue();
let b3= ss.getRange(i,4).getValue();
let b4= ss.getRange(i,5).getValue();
let b5= ss.getRange(i,6).getValue();
var data="<table>"
+"<tr>"
+"<th> MÃ SINH VIÊN </th><th> HỌ VÀ TÊN </th><th> LỚP </th> <th>MÔN TOÁN </th><th> Môn Lý</th><th>Môn Hóa</th>"
+"</tr> "
+"<tr>"
+"<td>"+obj+"</td><td>"+b1+"</td><td>"+b2+"</td><td>"+b3+"</td><td>"+b4+"</td><td>"+b5+"</td>"
+"</tr> </table>";
return data;
}
}
if (flag==1){
var data = "<span style = 'font-size:1.5em; color:red'>KHÔNG TỒN TẠI MÃ SINH VIÊN NÀY NÀY!</span>";
return data;
}
};
Mã trên file Index.html
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
<style>
table{
align: middle;
font-family: times;
border-collapse: collapse;
width: 50%;
}
td{
border: 1px solid #000000;
text-align: center;
padding: 8px;
}
th{
border: 1px solid #000000;
background-color: yellow;
text-align: center;
padding: 8px;
}
tr:nth-child(even){
background-color: #dddddd;
}
</style>
</head>
<body>
<p class="h4 mb-4 text-center" style="color: blue;">TÌM KẾT QUẢ HỌC TẬP CỦA SINH VIÊN</p>
<form align="center">
<div class="mb-1">
<div class="form-check form-check-inline">
<label style="font-weight: bold;" for="id" class="form-label">MÃ SINH VIÊN:</label>
</div>
<div class="form-check form-check-inline">
<input type="text" id="id" name="id" class="form-control form-control-sm" placeholder="Điền mã sinh viên" required>
</div>
</div>
<button type="button" class="btn btn-primary" onclick="info()">Lấy thông tin</button>
</form>
<hr>
<div align="center" id="result"></div>
<script>
function info(){
let msv= document.querySelector('#id').value;
let updateLocation = document.querySelector('#result');
updateLocation.innerHTML = "Đang lấy dữ liệu...";
function onFailure(error){
let warning = "<span style='color:red'>"+error+"</span>";
updateLocation.innerHTML=warning;
};
function onSuccess(response){
let result = "<span style='color: black'>"+response+"</span>";
updateLocation.innerHTML=result;
};
google.script.run.withFailureHandler(onFailure)
.withSuccessHandler(onSuccess)
.submitData(msv);
};
</script>
</body>
</html>