在单元格中搜索术语

时间:2015-10-21 02:25:50

标签: google-apps-script google-sheets google-spreadsheet-api

我正在尝试将电子邮件中的银行余额编号提取到Google Spreadsheets中。到目前为止,我有一个谷歌脚本抓取电子邮件,然后将其粘贴到rawcontent形式的谷歌电子表格。您可以在下面看到正在粘贴的RawContent。 (这不是我的银行余额或卡片,它是一个模板,已被使用并从我的银行网站上删除,以查找电子邮件的草稿。

    MIME-Version: 1.0
    Received: by 10.79.112.196 with HTTP; Tue, 20 Oct 2015 18:13:30 -0700 (PDT)
    Date: Wed, 21 Oct 2015 02:13:30 +0100
    Delivered-To: liamnagle5@gmail.com
    Message-ID: <CAL9nrMo3OXzMsPUMpXjOO1AEg_u72czoYLEQLeWz emRfJ0tfw@mail.gmail.com>
    Subject: BB TEST
    From: Liam Nagle <liamnagle5@gmail.com>
    To: Liam Nagle <liamnagle5@gmail.com>
    Content-Type: multipart/alternative; boundary=001a114d944e1c2fac052293164b

    --001a114d944e1c2fac052293164b
    Content-Type: text/plain; charset=UTF-8
    Content-Transfer-Encoding: quoted-printable

    Dear Mr. Broe,

    Your weekly account summary for
    account ending 6920 is below:

    Current Balance as at 12:30 26 Sep:
    =C2=A32500.00+
    Available Balance as at 12:30 26 Sep:
    =C2=A32700.00+

    RECENT TRANSACTIONS:
    25Sep Transfer =C2=A310.59-
    25Sep Cheque deposit 150.00+
    24Sep Direct Debit =C2=A33.60-
    23Sep Standing order =C2=A323.50-
    21Sep CC payment =C2=A349.00-

    Regards,

    Santander Alerts

    --001a114d944e1c2fac052293164b
    Content-Type: text/html; charset=UTF-8
    Content-Transfer-Encoding: quoted-printable

    <div dir=3D"ltr"><span style=3D"color:rgb(102,102,102);font-family:Verdana,=
    Arial,Helvetica,sans-serif;font-size:11.04px;letter-spacing:-0.1104px;line-=
    height:17.9952px">Dear Mr. Broe,</span><br style=3D"margin:0px;color:rgb(10=
    2,102,102);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:11.04px=
    ;letter-spacing:-0.1104px;line-height:17.9952px"><br style=3D"margin:0px;co=
    lor:rgb(102,102,102);font-family:Verdana,Arial,Helvetica,sans-serif;font-si=
    ze:11.04px;letter-spacing:-0.1104px;line-height:17.9952px"><span style=3D"c=
    olor:rgb(102,102,102);font-family:Verdana,Arial,Helvetica,sans-serif;font-s=
    ize:11.04px;letter-spacing:-0.1104px;line-height:17.9952px">Your weekly acc=
    ount summary for</span><br style=3D"margin:0px;color:rgb(102,102,102);font-=
    family:Verdana,Arial,Helvetica,sans-serif;font-size:11.04px;letter-spacing:=
    -0.1104px;line-height:17.9952px"><span style=3D"color:rgb(102,102,102);font=
    -family:Verdana,Arial,Helvetica,sans-serif;font-size:11.04px;letter-spacing=
    :-0.1104px;line-height:17.9952px">account ending 6920 is below:</span><br s=
    tyle=3D"margin:0px;color:rgb(102,102,102);font-family:Verdana,Arial,Helveti=
    ca,sans-serif;font-size:11.04px;letter-spacing:-0.1104px;line-height:17.995=
    2px"><br style=3D"margin:0px;color:rgb(102,102,102);font-family:Verdana,Ari=
    al,Helvetica,sans-serif;font-size:11.04px;letter-spacing:-0.1104px;line-hei=
    ght:17.9952px"><span style=3D"color:rgb(102,102,102);font-family:Verdana,Ar=
    ial,Helvetica,sans-serif;font-size:11.04px;letter-spacing:-0.1104px;line-he=
    ight:17.9952px">Current Balance as at 12:30 26 Sep:=C2=A0</span><br style=
    =3D"margin:0px;color:rgb(102,102,102);font-family:Verdana,Arial,Helvetica,s=
    ans-serif;font-size:11.04px;letter-spacing:-0.1104px;line-height:17.9952px"=
    ><span style=3D"color:rgb(102,102,102);font-family:Verdana,Arial,Helvetica,=
    sans-serif;font-size:11.04px;letter-spacing:-0.1104px;line-height:17.9952px=
    ">=C2=A32500.00+</span><br style=3D"margin:0px;color:rgb(102,102,102);font-=
    family:Verdana,Arial,Helvetica,sans-serif;font-size:11.04px;letter-spacing:=
    -0.1104px;line-height:17.9952px"><span style=3D"color:rgb(102,102,102);font=
    -family:Verdana,Arial,Helvetica,sans-serif;font-size:11.04px;letter-spacing=
    :-0.1104px;line-height:17.9952px">Available Balance as at 12:30 26 Sep:=C2=
    =A0</span><br style=3D"margin:0px;color:rgb(102,102,102);font-family:Verdan=
    a,Arial,Helvetica,sans-serif;font-size:11.04px;letter-spacing:-0.1104px;lin=
    e-height:17.9952px"><span style=3D"color:rgb(102,102,102);font-family:Verda=
    na,Arial,Helvetica,sans-serif;font-size:11.04px;letter-spacing:-0.1104px;li=
    ne-height:17.9952px">=C2=A32700.00+</span><br style=3D"margin:0px;color:rgb=
    (102,102,102);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:11.0=
    4px;letter-spacing:-0.1104px;line-height:17.9952px"><br style=3D"margin:0px=
    ;color:rgb(102,102,102);font-family:Verdana,Arial,Helvetica,sans-serif;font=
    -size:11.04px;letter-spacing:-0.1104px;line-height:17.9952px"><span style=
    =3D"color:rgb(102,102,102);font-family:Verdana,Arial,Helvetica,sans-serif;f=
    ont-size:11.04px;letter-spacing:-0.1104px;line-height:17.9952px">RECENT TRA=
    NSACTIONS:</span><br style=3D"margin:0px;color:rgb(102,102,102);font-family=
    :Verdana,Arial,Helvetica,sans-serif;font-size:11.04px;letter-spacing:-0.110=
    4px;line-height:17.9952px"><span style=3D"color:rgb(102,102,102);font-famil=
    y:Verdana,Arial,Helvetica,sans-serif;font-size:11.04px;letter-spacing:-0.11=
    04px;line-height:17.9952px">25Sep Transfer =C2=A310.59-</span><br style=3D"=
    margin:0px;color:rgb(102,102,102);font-family:Verdana,Arial,Helvetica,sans-=
    serif;font-size:11.04px;letter-spacing:-0.1104px;line-height:17.9952px"><sp=
    an style=3D"color:rgb(102,102,102);font-family:Verdana,Arial,Helvetica,sans=
    -serif;font-size:11.04px;letter-spacing:-0.1104px;line-height:17.9952px">25=
    Sep Cheque deposit 150.00+</span><br style=3D"margin:0px;color:rgb(102,102,=
    102);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:11.04px;lette=
    r-spacing:-0.1104px;line-height:17.9952px"><span style=3D"color:rgb(102,102=
    ,102);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:11.04px;lett=
    er-spacing:-0.1104px;line-height:17.9952px">24Sep Direct Debit =C2=A33.60-<=
    /span><br style=3D"margin:0px;color:rgb(102,102,102);font-family:Verdana,Ar=
    ial,Helvetica,sans-serif;font-size:11.04px;letter-spacing:-0.1104px;line-he=
    ight:17.9952px"><span style=3D"color:rgb(102,102,102);font-family:Verdana,A=
    rial,Helvetica,sans-serif;font-size:11.04px;letter-spacing:-0.1104px;line-h=
    eight:17.9952px">23Sep Standing order =C2=A323.50-</span><br style=3D"margi=
    n:0px;color:rgb(102,102,102);font-family:Verdana,Arial,Helvetica,sans-serif=
    ;font-size:11.04px;letter-spacing:-0.1104px;line-height:17.9952px"><span st=
    yle=3D"color:rgb(102,102,102);font-family:Verdana,Arial,Helvetica,sans-seri=
    f;font-size:11.04px;letter-spacing:-0.1104px;line-height:17.9952px">21Sep C=
    C payment =C2=A349.00-</span><br style=3D"margin:0px;color:rgb(102,102,102)=
    ;font-family:Verdana,Arial,Helvetica,sans-serif;font-size:11.04px;letter-sp=
    acing:-0.1104px;line-height:17.9952px"><br style=3D"margin:0px;color:rgb(10=
    2,102,102);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:11.04px=
    ;letter-spacing:-0.1104px;line-height:17.9952px"><span style=3D"color:rgb(1=
    02,102,102);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:11.04p=
    x;letter-spacing:-0.1104px;line-height:17.9952px">Regards,</span><br style=
    =3D"margin:0px;color:rgb(102,102,102);font-family:Verdana,Arial,Helvetica,s=
    ans-serif;font-size:11.04px;letter-spacing:-0.1104px;line-height:17.9952px"=
    ><br style=3D"margin:0px;color:rgb(102,102,102);font-family:Verdana,Arial,H=
    elvetica,sans-serif;font-size:11.04px;letter-spacing:-0.1104px;line-height:=
    17.9952px"><span style=3D"color:rgb(102,102,102);font-family:Verdana,Arial,=
    Helvetica,sans-serif;font-size:11.04px;letter-spacing:-0.1104px;line-height=
    :17.9952px">Santander Alerts</span></div>

    --001a114d944e1c2fac052293164b--

我希望摆脱这个问题的地方是:

    Current Balance as at 12:30 26 Sep:
    =C2=A32500.00+
    Available Balance as at 12:30 26 Sep:
    =C2=A32700.00+

从这里我想提取数字2500.002700.00=C2=A3部分表示以RawContent形式编写的£。在提取了两个数字之后,我希望将这些数字分配给另一个工作表上的两个单元格,然后使用该数据来计算财务计划等。

1 个答案:

答案 0 :(得分:1)

您可以使用公式=REGEXEXTRACT(E4,"=C2=A3(\d+\.\d{2})\+")来获得第一个匹配,但第二个匹配将会有点棘手。 由于您已经在使用脚本,我会编写另一个快速函数来提取这些值。

function getBalance(){
  var data = SpreadsheetApp.getActiveSheet().getRange(1,1).getValue();
  var re = /=C2=A3(\d+\.\d{2})\+/g;
  var results = [re.exec(data)[1], re.exec(data)[1]];
  return results;
}

这将获取文本,通过使用原始£前缀标识它们并将它们返回到数组中来提取两个可用余额。

然后,您甚至可以从电子表格中运行=GETBALANCE(),它会在两个单独的行中为您提供余额作为输出。