Я новичок вactjs, у меня есть файл excel (sample.xlsx) на моем диске Google, и я хочу прочитать данные этого файла в моем проекте activjs. Для этого я устанавливаю Google-таблицу, используя npm install google-spreadsheet
. Я следую этим инструкциям, чтобы разрешить доступ к файлу sample.xlsx (упоминается в https://www.npmjs.com/package/google-spreadsheet):
Setup Instructions
Go to the Google Developers Console
Select your project or create a new one (and then select it)
Enable the Drive API for your project
In the sidebar on the left, expand APIs & auth > APIs
Search for "drive"
Click on "Drive API"
click the blue "Enable API" button
Create a service account for your project
In the sidebar on the left, expand APIs & auth > Credentials
Click blue "Add credentials" button
Select the "Service account" option
Select "Furnish a new private key" checkbox
Select the "JSON" key type option
Click blue "Create" button
your JSON key file is generated and downloaded to your machine (it is the only copy!)
note your service account's email address (also available in the JSON key file)
Share the doc (or docs) with your service account using the email noted above
для опции совместного использования последнего шага файла sample.xlsx выглядит следующим образом:
![sample.xlsx](https://i.stack.imgur.com/vgy7T.png)
и код, который я использовал для просмотра содержимого файла sample.xlsx:
import React, { Component } from 'react';
var GoogleSpreadsheet = require('google-spreadsheet');
var async = require('async');
// spreadsheet key is the long id in the sheets URL
var doc = new GoogleSpreadsheet('1tLsrRTmQ0-D2aCYvYd6ZUQkhrh-XkIVKVb5ARYyxvM0');
var sheet;
async.series([
function setAuth(step) {
// see notes below for authentication instructions!
var creds = require('./ReactChart-a540fe85ca33.json');
doc.useServiceAccountAuth(creds, step);
},
function getInfoAndWorksheets(step) {
doc.getInfo(function(err, info) {
console.log('Loaded doc: '+info.title+' by '+info.author.email);
sheet = info.worksheets[0];
console.log('sheet 1: '+sheet.title+' '+sheet.rowCount+'x'+sheet.colCount);
step();
});
},
function managingSheets(step) {
doc.addWorksheet({
title: 'my new sheet'
}, function(err, sheet) {
// change a sheet's title
sheet.setTitle('new title'); //async
//resize a sheet
sheet.resize({rowCount: 50, colCount: 20}); //async
sheet.setHeaderRow(['name', 'age', 'phone']); //async
// removing a worksheet
sheet.del(); //async
step();
});
}
], function(err){
if( err ) {
console.log('Error: '+err);
}
});
class App extends Component {
constructor(props){
super(props);
this.state = {
}
}
componentWillMount(){
}
render() {
var stylePadding={
width: 600
}
return (
<div className="App" style={stylePadding}>
<div className="">
<h2>Welcome to React</h2>
</div>
</div>
);
}
}
export default App;
Я не знаю, почему я получаю эту ошибку:
Failed to load https://accounts.google.com/o/oauth2/token: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
спасибо за любую помощь