Bootstrap Progress Bar借助应用程序脚本变量

发布于 2025-02-12 21:22:38 字数 440 浏览 2 评论 0原文

我在应用程序脚本中有这个Google Sheet Cell计数器,我不知道如何使用“百分比”变量设置Bootstrap Progress Bar。

gs

function cellCounter() {

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheets = ss.getSheets();
  var cells = 0;
  sheets.forEach(function(sheet){
    cells = cells + sheet.getMaxRows() * sheet.getMaxColumns();
  });
  var division = cells/10000000*100;
  var percentage = +division.toFixed(0);
  return ( "
              

I have this Google Sheet cell counter in Apps Script and I don't know how to set the bootstrap progress bar with the "percentage" variable.

GS

function cellCounter() {

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheets = ss.getSheets();
  var cells = 0;
  sheets.forEach(function(sheet){
    cells = cells + sheet.getMaxRows() * sheet.getMaxColumns();
  });
  var division = cells/10000000*100;
  var percentage = +division.toFixed(0);
  return ( "???? Cada documento de Google Sheets tiene capacidad para diez millones de celdas. Has usado el <strong>" + percentage + "%</strong> del total con <strong>" + cells + " celdas</strong>." );
}

HTML

<div class="progress">
<div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100" style="width: 75%"></div>
</div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寒尘 2025-02-19 21:22:38

使用 nofollow noreferrer“> force portect scrinting scriptlets

  • 这使您可以通过应用脚本变量使用&lt;?!= ... ?

  let size;
  
  function doGet() {
    size = cellCounter();
    return HtmlService.createTemplateFromFile("html.html").evaluate();
  }
  
  function cellCounter() {
  
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheets = ss.getSheets();
    var cells = 0;
    sheets.forEach(function(sheet){
      cells = cells + sheet.getMaxRows() * sheet.getMaxColumns();
    });
    var division = cells/10000000*100;
    var percentage = +division.toFixed(0);
    return percentage;
  }   

​强> html.html:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous" />
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
  </head>
  <body>
    <div class="progress">
      <div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100" style="width: <?!= size ?>%">Hello </div>
    </div>
  </body>
</html>

Use Force-printing scriptlets

  • This allows you to pass Apps Script variables into your html syntax with <?!= ... ?>
  • For this, the variable to be passed must be declared globally

Sample for a Webapp (please adapt it to your dialog as needed):

GS

  let size;
  
  function doGet() {
    size = cellCounter();
    return HtmlService.createTemplateFromFile("html.html").evaluate();
  }
  
  function cellCounter() {
  
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheets = ss.getSheets();
    var cells = 0;
    sheets.forEach(function(sheet){
      cells = cells + sheet.getMaxRows() * sheet.getMaxColumns();
    });
    var division = cells/10000000*100;
    var percentage = +division.toFixed(0);
    return percentage;
  }   

html.html:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous" />
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
  </head>
  <body>
    <div class="progress">
      <div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100" style="width: <?!= size ?>%">Hello </div>
    </div>
  </body>
</html>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文