Google sheet, App Script, Web app | Tạo button Print để In nội dung trên trang html có ngắt trang in
Giáo án link (giaoan.link) chia sẻ tiếp đến các bạn project Google sheet, App Script, Web app | Tạo button Print để In nội dung trên trang html có ngắt trang in. Qua ví dụ này bạn sẽ biết cách tạo một nút “Print” để in nội dung trên thẻ div html và bạn có thể áp dụng vào nhiều dự án riêng của bạn. Dưới đây là code mẫu và video hướng dẫn để bạn tham khảo.
Xem thêm nhiều project excel khác:
- Apsscript Radio Button và Input – Sự phụ thuộc của input vào Radio button
- Bạn sử dụng zalo và bị báo đầy ổ đĩa,phải làm sao
- Google sheet Webapp Login form Tocken quản lý phiên đăng nhập, gửi mail lấy lại thông tin đăng nhập
- Chuyển bảng dữ liệu từ file PDF vào Excel
- Google sheet Apps script Hệ thống duyệt hồ sơ sinh viên – Form nhập liệu, Login duyêt, gửi mail
- Tool VBA Form Excel xử lí chuỗi tạo folder hàng loạt theo danh sách
- Google sheet webapp | Quản lý quán Cà phê – Phân quyền- Quét QR chấm công- Quản lý nhân viên-Báo cáo
- 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
Code file “Code.gs”
function doGet() {
return HtmlService.createTemplateFromFile('index').evaluate().setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
}
Code file “index.html”
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<style>
.table,tr,td{
text-align: justify;
width:"100%";
border: 2px solid red;
}
</style>
<script>
function Print(DivID) {
var iPrint = document.getElementById(DivID).innerHTML;
var docprint=window.open("","");
docprint.document.open();
docprint.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"');
docprint.document.write('<head><meta name="viewport" content="width=device-width,initial-scale=1.0">');
docprint.document.write('<title>Pritting example</title>');
docprint.document.write('<style type="text/css">@page {size: A4; margin: 2cm 2cm 2cm 2cm;}'); //top-right-buttom-left
docprint.document.write('table,td,tr{ border:1px solid red; text-align: justify; padding: 5px; border-collapse: collapse; width: 100%;}</style>');
docprint.document.write('</head><center><body onLoad="self.print()">');
docprint.document.write(iPrint);
docprint.document.write('</body></center></html>');
docprint.document.close();
docprint.focus();
}
</script>
</head>
<body>
<!--Printting-->
<div id='PrintDiv'>
<table>
<tr >
<td>
NỘI DUNG BẠN CẦN IN BẠN ĐẶT VÀO ĐÂY
</td>
</tr>
</table>
<div style='page-break-before: always;'></div>
<span>NOI DUNG O TRANG THU HAI</span>
</div>
<!--Printting-->
<br>
<div style="text-align:center">
<input type="button" class="btn btn-secondary" name="btnprint" value="PRINT" onclick="Print('PrintDiv')" style="width:20%">
</div>
</body>
</html>