我是新手,我正在开发将csv导入到Google表格的小项目, 关于部分导入CSV到谷歌表,并在我成功的电子表格中创建工作表。如何访问我创建的工作表?下面是用于在电子表格ID中创建工作表的代码。谢谢!
$client = getClient();
$service = new Google_Service_Sheets($client);
$valueInputOption = 'USER_ENTERED';
$spreadsheetId = 'xxxxxxxxxxxxSPREADSHEETIDxxxxxxxxxx';
$title = date('m-d');
$body = new Google_Service_Sheets_BatchUpdateSpreadsheetRequest(array( 'requests' => array('addSheet' => array('properties' => array('title' => $title )))));
$result = $service->spreadsheets->batchUpdate($spreadsheetId, $body);
答案 0 :(得分:0)
访问Google电子表格数据的方式如下:
/*
Assume the data structure of the Google Spreadsheet is:
NAME COLOR
==================
Apple red
Mango yellow
*/
// define sheet url
var dataSheetUrl =
'https://docs.google.com/spreadsheets/d/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/edit';
// open one of the sheet named 'Fruit'
var dataSheet = SpreadsheetApp.openByUrl(dataSheetUrl).getSheetByName('Fruit');
// get sheet data
var data = dataSheet.getDataRange().getValues();
// loop through each row data and then log it
for (var i = 1, j = data.length; i < j; i++) {
Logger.log('NAME: ' + data[i][0]);
Logger.log('AGE: ' + data[i][1]);
}