1
+ <?php
2
+ /**
3
+ * Copyright 2022 Google Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ // [START slides_create_sheets_chart]
19
+ use Google \Client ;
20
+ use Google \Service \Drive ;
21
+ use Google \Service \Slides ;
22
+ use Google \Service \Slides \Request ;
23
+
24
+
25
+ function createSheetsChart ($ presentationId , $ pageId , $ spreadsheetId , $ sheetChartId )
26
+ {
27
+ /* Load pre-authorized user credentials from the environment.
28
+ TODO(developer) - See https://developers.google.com/identity for
29
+ guides on implementing OAuth2 for your application. */
30
+ $ client = new Google \Client ();
31
+ $ client ->useApplicationDefaultCredentials ();
32
+ $ client ->addScope (Google \Service \Drive::DRIVE );
33
+ $ slidesService = new Google_Service_Slides ($ client );
34
+ // Embed a Sheets chart (indicated by the spreadsheet_id and sheet_chart_id) onto
35
+ // a page in the presentation. Setting the linking mode as "LINKED" allows the
36
+ // chart to be refreshed if the Sheets version is updated.
37
+ try {
38
+ //creating new presentaion chart
39
+ $ presentationChartId = 'MyEmbeddedChart ' ;
40
+ $ emu4M = array ('magnitude ' => 4000000 , 'unit ' => 'EMU ' );
41
+ $ requests = array ();
42
+ $ requests [] = new Google_Service_Slides_Request (
43
+ array (
44
+ 'createSheetsChart ' => array (
45
+ 'spreadsheetId ' => $ spreadsheetId ,
46
+ 'chartId ' => $ sheetChartId ,
47
+ 'linkingMode ' => 'LINKED ' ,
48
+ 'elementProperties ' => array (
49
+ 'pageObjectId ' => $ pageId ,
50
+ 'size ' => array (
51
+ 'height ' => $ emu4M ,
52
+ 'width ' => $ emu4M
53
+ ),
54
+ 'transform ' => array (
55
+ 'scaleX ' => 1 ,
56
+ 'scaleY ' => 1 ,
57
+ 'translateX ' => 100000 ,
58
+ 'translateY ' => 100000 ,
59
+ 'unit ' => 'EMU '
60
+ )
61
+ )
62
+ )
63
+ ));
64
+
65
+ // Execute the request.
66
+ $ batchUpdateRequest = new Google_Service_Slides_BatchUpdatePresentationRequest (array (
67
+ 'requests ' => $ requests
68
+ ));
69
+ $ response = $ slidesService ->presentations ->batchUpdate ($ presentationId , $ batchUpdateRequest );
70
+ printf ("Added a linked Sheets chart with ID: %s \n" , $ response ->getPresentationId ());
71
+ return $ response ;
72
+ } catch (Exception $ e ) {
73
+ echo 'Message: ' . $ e ->getMessage ();
74
+ }
75
+ }
76
+
77
+ // [END slides_create_sheets_chart]
78
+ require 'vendor/autoload.php ' ;
79
+ createSheetsChart ('12ZqIbNsOdfGr99FQJi9mQ0zDq-Q9pdf6T3ReVBz0Lms ' , 'abcd1234 ' , '1sN_EOj0aYp5hn9DeqSY72G7sKaFRg82CsMGnK_Tooa8 ' , 122 );
80
+ ?>
0 commit comments