Google脚本可在importrange上过滤掉整个工作表中不需要的字符

时间:2019-07-14 14:14:45

标签: google-apps-script google-sheets

所以我想运行一个正则表达式来去除所有非ASCII。
正则表达式为:[^ \ x00- \ x7F]

是否有办法在导入时执行此操作,或者我需要导入所有内容并逐个单元查找字符,然后将其替换为“”?

我用来导入所有内容的函数是:

function createNewSheet(newSheetName) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  yourNewSheet = ss.insertSheet();
  yourNewSheet.setName(newSheetName); 
  yourNewSheet.getRange('A1').setFormula('=query(IMPORTRANGE(\"https://docs.google.com/spreadsheets/d/xxxxxxxxxxxxxxxxxx/edit#gid=0\", \"Master!A:K\"), \"SELECT Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10, Col11 where Col1 = \'"& \'Select Your Event\'!A3 &"\' Order By Col9, Col10",1)')
  pasteValues(newSheetName);
  SpreadsheetApp.flush();
  yourNewSheet.autoResizeColumns(7,4);
}

1 个答案:

答案 0 :(得分:1)

我从以下答案中找到了解决方案: Google Apps Script for Multiple Find and Replace in Google Sheets

我能够实现这种方式所需的正则表达式,并扫描并替换工作表中的所有非ASCII字符

from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk
from tkinter import messagebox, Button, Tk, BooleanVar
from tkinter.ttk import Checkbutton
from matplotlib.figure import Figure
import matplotlib
matplotlib.use('TkAgg')


class GUI:

    fig = Figure()
    sub = fig.add_subplot(1, 1, 1)

    def __init__(self, root):
        self.root = root
        self.root.title("Testing")
        self.setupTk()

    def setupTk(self):

        self.var = BooleanVar()
        self.var.set(True)
        self.check_button = Checkbutton(
            self.root, variable=self.var, text='Direvative', command=self.cb)
        self.check_button.pack(side='left')

        self.quit_button = Button(master=self.root, text='Quit', command=self._quit)
        self.quit_button.pack(side='right')

        self.canvas = FigureCanvasTkAgg(self.fig, master=self.root)
        self.canvas.get_tk_widget().pack(side='top', fill='both', expand=1)
        self.canvas._tkcanvas.pack(side='top', fill='both', expand=1)

        self.toolbar = NavigationToolbar2Tk(self.canvas, self.root)
        self.toolbar.update()

        self.root.protocol("WM_DELETE_WINDOW", self._quit)

    def cb(self):
        print(self.var.get())

    def _quit(self):
        self.root.destroy()


if __name__ == '__main__':
    root = Tk()
    mod = GUI(root)
    root.mainloop()