如何为Google表格制作循环脚本?

时间:2018-11-10 19:07:07

标签: javascript loops google-apps-script google-sheets

我想拥有一个脚本,该脚本将使用脚本将文本更改为超链接。我在D1:D的Google工作表中有D列,例如:

import React, { Component } from "react";
import Fields from "../components/Fields";

export default class Form extends Component {
  state = {
    tripStart: "",
    tripEnd: ""
  };

  handleChange = ({ target: { value, name } }) =>
    this.setState(
      {
        [name]: value
      },
      () =>
        this.setState({
          name: `${this.state.tripStart} to ${this.state.tripEnd}`
        })
    );

  handleSubmit = e => {
    e.preventDefault();
    const { name } = this.state;
    alert(name);
  };

  render = () => (
    <Fields
      {...this.state}
      handleSubmit={this.handleSubmit}
      onHandleChange={this.handleChange}
    />
  );
}

当前,我正在使用此脚本,该脚本仅用于名为12346 34566 23456 23455... and so on... 的特定标签。

Sheet1

是否可以使用循环来缩短脚本?

1 个答案:

答案 0 :(得分:1)

您可以使用以下内容:

i = 1
while (true) {
    var range = ss.getRange("D" + i);
    var value = range.getValue();
    if(value == "") {
        break;
    }
    range.setValue('=HYPERLINK("https://sellercentral.amazon.com/hzefad/orders/&orderId='+value+'","'+value+'")');
    i++;
}