简体   繁体   English

如何只允许在 Google 表格中选中一个复选框

[英]How do I allow for only one checkbox to be checked in Google Sheets

Please reference my spreadsheet for help answering this question: https://docs.google.com/spreadsheets/d/1rNH-TZFa51EL5CwcSGTj5TR-x9V46ajBFyXbTeXYqBI/edit?usp=sharing请参考我的电子表格以帮助回答这个问题: https://docs.google.com/spreadsheets/d/1rNH-TZFa51EL5CwcSGTj5TR-x9V46ajBFyXbTeXYqBI/edit?usp=sharing

I have created a Gooogle Sheet for my customers to select which features they want to purchase for a package deal.我为我的客户创建了一个 Google 表格 select,他们想要购买 package 交易的功能。 I figured out how to sum the prices for a total, but I am having trouble figuring out how only to allow customers to select only a certain number of boxes per SECTION so they won't get overcharged for things they do not need/select more boxes than they should.我想出了如何对总价格求和,但我无法弄清楚如何只允许客户 select 每个部分只允许一定数量的盒子,这样他们就不会因为不需要的东西而被多收/选择更多盒子比他们应该。

Each package comes with a certain number of items you can get from a particular section of the sheet.每个 package 都带有一定数量的物品,您可以从工作表的特定部分获得。 For example, the base package allows for ONE out of 7 additional pages, while the advanced package allows for 4 out of 7 additional pages.例如,基本 package 允许 7 个附加页面中的一个,而高级 package 允许 7 个附加页面中的 4 个。

Obviously, I do not want the customer to select SIX additional pages if they want the base package because they only pay for ONE when selecting the base package.显然,如果客户想要基本的 package,我不希望客户增加六页 select,因为他们在选择基本 ZEFE90A8E604A7C840E88D03A67F6B7D8 时只需支付一页。 I need the rest of the additional page boxes to become deactivated if they choose the base package, then choose one addition page, or if they select the advanced package and select four additional pages, and so on. I need the rest of the additional page boxes to become deactivated if they choose the base package, then choose one addition page, or if they select the advanced package and select four additional pages, and so on.

The same thing goes with the forms. forms 也是如此。 The advanced package only lets you select two interactive forms, so I do not want them to have the option of choosing more than two boxes.先进的 package 只让你 select 两个交互式 forms,所以我不希望他们有选择两个以上的盒子的选项。 This option should ONLY be allowed if they have selected the premium package deal.仅当他们选择了高级 package 交易时,才应允许此选项。

Again, as you can see, #4, for the marketing programs, of course, customers won't need both the Market Starter AND the Market Pro;同样,正如您所看到的,#4,对于营销计划,客户当然不会同时需要 Market Starter 和 Market Pro; they need only to select ONE of these options.他们只需要 select 这些选项之一。 I would like the ability to deactivate one box if they choose the other.如果他们选择另一个,我希望能够停用一个盒子。

I have read a lot of the other articles referring to OnEdit, but I have no idea what that is, nor do I know anything about code.我已经阅读了很多其他关于 OnEdit 的文章,但我不知道那是什么,我对代码也一无所知。 I am quite surprised that I got as far as I did on this sheet, I hope my question was thorough, but if not.我很惊讶我在这张纸上所做的一切,我希望我的问题是彻底的,但如果不是。 feel free to ask any questions.随意问任何问题。 Please help!!请帮忙!!

You can use Data Validation instead.您可以改用数据验证。

Unfortunately Sheets doesn't have radio buttons for the Sheets interface, but Data Validation is pretty much the same.不幸的是,Sheets 没有用于 Sheets 界面的单选按钮,但数据验证几乎相同。 You can follow the steps to create it here .您可以按照步骤在此处创建它。

You can use the following code which runs onEdit and works as if you have radio buttons:您可以使用以下代码运行 onEdit 并像您有单选按钮一样工作:

Code:代码:

  function onEdit(evt) {

  var range = evt.range;
  var val = range.getValue();
  var row = range.getRow();
  var col = range.getColumn();

  // -------------------------------------
  // Only 1 checkbox per row can be ticked ---
  // i=6  because we start at Column F, then i<9 because we stop at H (Col 8)


  for(var i = 6;i<9;i++){
    if(i == col) continue;

    // We check that we are on the right row (26) and columns (6,7,8)

    if (row == 26 && col == 6 || col == 7 || col == 8){

      SpreadsheetApp.getActiveSheet().getRange(row,i).setValue('FALSE');    
    }
  }
}

Note :注意

Sometimes keeping things simple, is much better than trying to do something a little bit more sophisticated.有时保持简单,比尝试做一些更复杂的事情要好得多。

You could have (by yourself) used a simple drop-down menu with the 3 packages: I've added a sheet illustrating this with the formula.您可以(自己)使用包含 3 个软件包的简单下拉菜单:我添加了一张表格,用公式说明了这一点。

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何隐藏Google表格中除一个以外的所有表格? - How do I hide all sheets except one in Google Sheets? 如何使用单元格的应用程序脚本将 Google 表格数据验证添加到列中,以仅允许输入颜色和十六进制颜色代码 - How do I add Google sheets data vaildation to a column using apps script for cells to only allow colors and hex color codes to be inputted 如何导出为 pdf,然后仅通过电子邮件发送我的 Google 表格文件的一个标签? - How do I export to pdf then email for only one tab of my google sheets file? 如果选中复选框,Google表格会隐藏行 - Google Sheets Script to Hide Row if Checkbox Checked 如何只清除谷歌表格上的数据而不清除公式? - How do I clear data only but not formulas on google sheets? Google 表格脚本:如何仅在名称包含特定文本的表格上运行脚本? - Google Sheets script: how do I run a script only on the sheets whose names contain particular text? 如何允许用户通过我自己的 Google Scripts Web 应用程序编辑我的表格文件? - How do I allow users to edit my Sheets file via my own Google Scripts Web App? 如何复制复选框值并使单元格在 Google 表格中保持可编辑? - How do i copy a checkbox value and keep the cell editable in Google Sheets? 当使用 Google 表格选中复选框时,向单个收件人发送合并邮件 - Send a merge mail to a single recipient when a checkbox is checked with google sheets Google 表格:防止在选中复选框后取消选中它 - Google Sheets: Prevent the unchecking of a checkbox after it has been checked
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM