是否可以在对PC上的工作表进行一些更改并成功同步到Google驱动器后,运行特定脚本(在Google端,在unix中使用某种类型的cron)从此工作表导入更改到Google日历服务? 附:我已经知道如何将更改从表格导入日历,问题是关于文档更改(编辑)的自动运行此导入过程。
答案 0 :(得分:1)
您可以查看有关Installable Triggers的文档,该文档可让Apps脚本在发生特定事件时自动运行功能。它与onOpen()
类似onEdit()
,但它们可以响应其他事件,但行为也不同。
您可以使用在用户修改电子表格中的值时运行的simple triggers for Google Apps。
function onEdit(event) { var ss = event.source.getActiveSheet(); var r = event.source.getActiveRange(); r.setComment("Last modified: " + (new Date())); }
触发器是可行的方法。这是一个简单的例子 从文档中直接拉出来:import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Scanner; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JPanel; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.XYPlot; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; import com.fazecast.jSerialComm.SerialPort; public class SerialDataRead { static SerialPort chosenPort; public static void main(String[] args) { // TODO Auto-generated method stub final JFrame window = new JFrame(); window.setTitle("Sensor graph GUI"); window.setSize(1200,800); window.setLayout(new BorderLayout()); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel basePanel = new JPanel(); basePanel.setSize(900, 700); final JComboBox portList = new JComboBox(); final JButton connectButton = new JButton("Connect"); JPanel topPanel = new JPanel(); window.add(topPanel, BorderLayout.NORTH); topPanel.add(portList); topPanel.add(connectButton); SerialPort[] portNames = SerialPort.getCommPorts(); for(int i =0; i < portNames.length; i++) portList.addItem(portNames[i].getSystemPortName()); final XYSeries series = new XYSeries("Serial port data reading"); final XYSeries series2 = new XYSeries("Serial port data reading"); XYSeriesCollection dataset = new XYSeriesCollection(series); JFreeChart chart = ChartFactory.createXYLineChart("Serial port reading", "Time (seconds)", "adc reading", dataset); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); NumberAxis domain = (NumberAxis) plot.getDomainAxis(); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); //domain.setRange(0.00, 40.00); rangeAxis.setRange(0.0, 505.0); window.add(new ChartPanel(chart), BorderLayout.CENTER); connectButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0){ if(connectButton.getText().equals("Connect")){ chosenPort = SerialPort.getCommPort(portList.getSelectedItem().toString()); chosenPort.setComPortTimeouts(SerialPort.TIMEOUT_SCANNER, 0, 0); if(chosenPort.openPort()){ connectButton.setText("Disconnect"); portList.setEnabled(false); } Thread thread = new Thread(){ @Override public void run(){ Scanner scanner = new Scanner(chosenPort.getInputStream()); int x =0; while(scanner.hasNextLine()){ String line = scanner.nextLine(); String[] values = line.split(","); int number = Integer.parseInt(values[0]); int number2 = Integer.parseInt(values[1]); series.add(x++, number); //series2.add(x++, number2); XYSeriesCollection my_data_series= new XYSeriesCollection(); // add series using addSeries method my_data_series.addSeries(series); // my_data_series.addSeries(series2); // JFreeChart XYLineChart=ChartFactory.createXYLineChart("Team - Number of Wins","Year","Win Count",my_data_series,PlotOrientation.VERTICAL,true,true,false); //window.repaint(); System.out.println(Integer.parseInt(values[1])); } scanner.close(); } }; thread.start(); }else{ chosenPort.closePort(); portList.setEnabled(true); connectButton.setText("Connect"); } } }); window.setVisible(true); }
在功能体内,你可以做各种各样的事情。如果你 然后需要访问授权服务(如Gmail,日历等) 您需要创建一个可安装的触发器。
希望这有帮助!