javascript表格快速入门(代码片段)

author author     2022-12-04     345

关键词:

const fs = require('fs');
const readline = require('readline');
const google = require('googleapis');

// If modifying these scopes, delete token.json.
const SCOPES = ['https://www.googleapis.com/auth/spreadsheets.readonly'];
// The file token.json stores the user's access and refresh tokens, and is
// created automatically when the authorization flow completes for the first
// time.
const TOKEN_PATH = 'token.json';

// Load client secrets from a local file.
fs.readFile('credentials.json', (err, content) => 
  if (err) return console.log('Error loading client secret file:', err);
  // Authorize a client with credentials, then call the Google Sheets API.
  authorize(JSON.parse(content), listMajors);
);

/**
 * Create an OAuth2 client with the given credentials, and then execute the
 * given callback function.
 * @param Object credentials The authorization client credentials.
 * @param function callback The callback to call with the authorized client.
 */
function authorize(credentials, callback) 
  const client_secret, client_id, redirect_uris = credentials.installed;
  const oAuth2Client = new google.auth.OAuth2(
      client_id, client_secret, redirect_uris[0]);

  // Check if we have previously stored a token.
  fs.readFile(TOKEN_PATH, (err, token) => 
    if (err) return getNewToken(oAuth2Client, callback);
    oAuth2Client.setCredentials(JSON.parse(token));
    callback(oAuth2Client);
  );


/**
 * Get and store new token after prompting for user authorization, and then
 * execute the given callback with the authorized OAuth2 client.
 * @param google.auth.OAuth2 oAuth2Client The OAuth2 client to get token for.
 * @param getEventsCallback callback The callback for the authorized client.
 */
function getNewToken(oAuth2Client, callback) 
  const authUrl = oAuth2Client.generateAuthUrl(
    access_type: 'offline',
    scope: SCOPES,
  );
  console.log('Authorize this app by visiting this url:', authUrl);
  const rl = readline.createInterface(
    input: process.stdin,
    output: process.stdout,
  );
  rl.question('Enter the code from that page here: ', (code) => 
    rl.close();
    oAuth2Client.getToken(code, (err, token) => 
      if (err) return console.error('Error while trying to retrieve access token', err);
      oAuth2Client.setCredentials(token);
      // Store the token to disk for later program executions
      fs.writeFile(TOKEN_PATH, JSON.stringify(token), (err) => 
        if (err) return console.error(err);
        console.log('Token stored to', TOKEN_PATH);
      );
      callback(oAuth2Client);
    );
  );


/**
 * Prints the names and majors of students in a sample spreadsheet:
 * @see https://docs.google.com/spreadsheets/d/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms/edit
 * @param google.auth.OAuth2 auth The authenticated Google OAuth client.
 */
function listMajors(auth) 
  const sheets = google.sheets(version: 'v4', auth);
  sheets.spreadsheets.values.get(
    spreadsheetId: '1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms',
    range: 'Class Data!A2:E',
  , (err, res) => 
    if (err) return console.log('The API returned an error: ' + err);
    const rows = res.data.values;
    if (rows.length) 
      console.log('Name, Major:');
      // Print columns A and E, which correspond to indices 0 and 4.
      rows.map((row) => 
        console.log(`$row[0], $row[4]`);
      );
     else 
      console.log('No data found.');
    
  );

快速入门javascript二(代码片段)

3、JavaScriptDOM3.1、DOM介绍DOM(DocumentObjectModel):文档对象模型。将HTML文档的各个组成部分,封装为对象。借助这些对象,可以对HTML文档进行增删改查的动态操作。3.2、Element元素的获取操作具体方法代码实现<!DOCTYPEhtml><htmllan... 查看详情

javaweb基础知识:javascript快速入门(代码片段)

JavaScript快速入门1.js生成文本<!--js一般是写在head标签里面--><script>document.write("我是天才!!");document.write("我是废才!!");</script>2.js生成标签<script>document.write(" 查看详情

javascript教程带你快速入门(代码片段)

JavaScript简介JavaScript(简称“JS”)是一种具有函数优先的轻量级,解释型或即时编译型的高级编程语言。JavaScript是基于原型编程、多范式的动态脚本语言,并且支持面向对象、命令式和声明式(如函数式编程... 查看详情

jquery快速入门(代码片段)

 jQueryjQuery介绍jQuery是一个轻量级的、兼容多浏览器的JavaScript库。jQuery使用户能够更方便地处理HTMLDocument、Events、实现动画效果、方便地进行Ajax交互,能够极大地简化JavaScript编程。它的宗旨就是:“Writeless,domore.“jQuer... 查看详情

jquery快速入门(代码片段)

  JQ介绍   jQuery是一个轻量级的,兼容多浏览器的JavaScript库(模块).  jQuery使用户能够更方便地处理HTMLDocument,Events,实现动画效果,方  便进行Ajax交互,能够极大地简化JavaScript编程.他的宗旨是:‘Writeless,do  more.‘ ... 查看详情

jquery快速入门(代码片段)

jQueryjQuery介绍jQuery是一个轻量级的、兼容多浏览器的JavaScript库。jQuery使用户能够更方便地处理HTMLDocument、Events、实现动画效果、方便地进行Ajax交互,能够极大地简化JavaScript编程。它的宗旨就是:“Writeless,domore.“jQuery的优势一... 查看详情

jquery快速入门(代码片段)

jQuery介绍jQuery是一个轻量级的、兼容多浏览器的JavaScript库。jQuery使用户能够更方便地处理HTMLDocument、Events、实现动画效果、方便地进行Ajax交互,能够极大地简化JavaScript编程。它的宗旨就是:“Writeless,domore.“jQuery的优势... 查看详情

javascript零基础入门|day1:javascript表格(代码片段)

🍅Java学习路线思维导图: Java学习路线思维导图🍅Java学习路线总结:搬砖工逆袭Java架构师🍅Java经典面试题大全:10万字208道Java经典面试题总结(附答案)🍅简介:Java领域优质创作者🏆、CSDN... 查看详情

javascript之es6快速入门(代码片段)

一、ES6语法指南后端项目搭建完毕,接下来就是前端页面了。不过在这之前需要一些准备工作。我们需要学习ES6的语法标准。什么是ES6?就是ECMAScript第6版标准。1、什么是ECMAScript?来看下前端的发展历程:web1.0时代:最初的... 查看详情

javascript之es6快速入门(代码片段)

一、ES6语法指南后端项目搭建完毕,接下来就是前端页面了。不过在这之前需要一些准备工作。我们需要学习ES6的语法标准。什么是ES6?就是ECMAScript第6版标准。1、什么是ECMAScript?来看下前端的发展历程:web1.0时代:最初的... 查看详情

javascript快速入门(代码片段)

...代表过去,能力代表现在,学习能力代表未来! 目录1.初始JavaScript1.1JavaScript是什么?1.2JavaScript能做的事情 1.3JavaScript和HTML和CSS的关系1.4JavaScript运行过程1.5JavaScript的组成2.前置知识2.1JavaScript的书写形式2.2输入输出3.语法概览3.1变量... 查看详情

5分钟快速入门javascript数据结构与算法的基础①javascript数据结构与算法系列(代码片段)

本文目录一、JavaScript的简介二、JavaScript的环境搭建三、JavaScript的基础(变量、常量、运算符、真假值)四、本章小结五、写在后面一、JavaScript的简介JavaScript是一门非常强大的编程语言。它也是最流行的编程语言之一&#x... 查看详情

5分钟快速入门javascript数据结构与算法的基础①javascript数据结构与算法系列(代码片段)

本文目录一、JavaScript的简介二、JavaScript的环境搭建三、JavaScript的基础(变量、常量、运算符、真假值)四、本章小结五、写在后面一、JavaScript的简介JavaScript是一门非常强大的编程语言。它也是最流行的编程语言之一&#x... 查看详情

javascript入门学习(代码片段)

JavaScript快速入门一、JavaScript简介JavaScript是目前最流行脚本语言,简称JSJavaScript编写在HTML页面中,由浏览器负责解释和执行JavaScript通常用来给HTML页面增加交互能力特点:☆为页面增加动画效果☆验证表单输入项有效... 查看详情

jquery快速入门(代码片段)

...么要用jQuery做同样的事,jQuery写起来极其简练 jQuery相当于JavaScript的第三方模块(原生的DOM是基础) jQuery的语法设计使得许多操作变得容易,如操作文档对象(document)、选择文档对象模型(DOM)元素、创建动画效果、处理事件... 查看详情

javascript快速入门(代码片段)

文件中引入JavaScript嵌入到HTML文件中在body或者head中添加script标签<script>varage=10;console.log(age);</script>引入js文件创建一个js文件varage=20;console.log(age);在html文件中src引入改文件<body><scriptsrc="./age.js"></script></body... 查看详情

less快速入门(代码片段)

...的是Less的官方文档(中文版),包含了Less语言以及利用JavaScript开发的用于将Less样式转换成CSS样式的Less.js工具。因为Less和CSS非常像,因此很容易学习。而且Less仅对CSS语言增加了少许方便的扩展,这就是Less如此易学的原因之一... 查看详情

jquery快速入门(代码片段)

 jQueryjQuery介绍jQuery是一个轻量级的、兼容多浏览器的JavaScript库。jQuery使用户能够更方便地处理HTMLDocument、Events、实现动画效果、方便地进行Ajax交互,能够极大地简化JavaScript编程。它的宗旨就是:“Writeless,domore.“jQuer... 查看详情