多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
【google sheet data insert into database】 前提需要下载后google sheet api,做对应的配置: ~~~ <?php require_once 'vendor/autoload.php'; $connect = mysqli_connect("localhost", "root", "", "test"); $keys = json_decode(file_get_contents("credential2.json")); $client = new Google_Client(); $cred = new Google_Auth_AssertionCredentials( $keys->client_email, array(Google_Service_Drive::DRIVE), $keys->private_key ); $client->setAssertionCredentials($cred); $service = new Google_Service_Sheets($client); $spreadsheetId = '1YTT5jalDj5HzspsNcx7qUmCxttUyKsQfNRO_XyKItoo'; $sheets = array('S1', 'S2'); foreach ($sheets as $number) { $range = ''.$number.'!A1:30'; $result = $service->spreadsheets_values->get($spreadsheetId, $range); $ranges = $result->getValues(); echo '<pre>'; print_r($ranges); echo '<hr/>'; if(is_array($ranges)) { foreach($ranges as $row => $value) { $data1 = mysqli_real_escape_string($connect, $value[0]); $data2 = mysqli_real_escape_string($connect, $value[1]); $data3 = mysqli_real_escape_string($connect, $value[3]); $sql = "INSERT INTO demo(list1, list2, list3) VALUES ('".$data1."', '".$data2."', '".$data3."')"; mysqli_query($connect, $sql); } } } ~~~ 选取google sheet的位置:S1表的A, B, D列: ![](https://box.kancloud.cn/3e9936b0b6de9a4063214f2a63955f7f_498x140.png) S2表的A, B, D列: ![](https://box.kancloud.cn/5585cad290832d056cc372c72951ac04_507x136.png) 插入数据表后的效果: ![](https://box.kancloud.cn/572feaf55e6e5c71ee1b961e9b421d17_384x318.png)