Học Ms excelKỹ năng vi tính

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:

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>

Video hướng dẫn thực hiện






giaoanppt

Giaoan.link trang chia sẽ giáo án điện tử, bài giảng powerpoint, template powerpoint, nguyên liệu làm bài giảng, tài liệu, biểu mẫu miễn phí!