For inserting texts-
'insertText' => [
'text' => "hello",
'location' => [
'index' => 1,
]
]
and for inserting images-
"insertInlineImage" => [
"location" => [
"index" => 1
],
"uri" => "https://www.gstatic.com/images/branding/product/1x/docs_64dp.png",
"objectSize" => [
"height"=> [
"magnitude"=> 10,
"unit" => "PT"
],
"width"=> [
"magnitude"=> 10,
"unit"=> "PT"
]
]
]
Now, I noticed that your question had been updated. From your updated question, unfortunately, I thought that in the current stage, your goal cannot be directly achieved. So, in this updated answer, as a workaround, how about using a table as follows?
$b = ["color" => ["color" => []], "dashStyle" => "SOLID", "width" => ["magnitude" => 0, "unit" => "PT"]];
$requests = [
new Google_Service_Docs_Request([
'insertTable' => [
'location' => ['index' => 1],
'columns' => 2,
'rows' => 1
]
]),
new Google_Service_Docs_Request([
"updateTableCellStyle" => [
"tableCellStyle" => [
"borderBottom" => $b,
"borderTop" => $b,
"borderLeft" => $b,
"borderRight" => $b,
],
"tableStartLocation" => ["index" => 2],
"fields" => "borderBottom,borderTop,borderLeft,borderRight"
]
]),
new Google_Service_Docs_Request([
"insertInlineImage" => [
"location" => [
"index" => 5
],
"uri" => "https://www.gstatic.com/images/branding/product/1x/docs_64dp.png",
"objectSize" => [
"height"=> [
"magnitude"=> 100,
"unit" => "PT"
],
"width"=> [
"magnitude"=> 100,
"unit"=> "PT"
]
]
]]),
new Google_Service_Docs_Request([
'insertText' => [
'text' => "hello1\nhello2\nhello3",
'location' => [
'index' => 8,
]
]]),
new Google_Service_Docs_Request([
"updateParagraphStyle" => [
"paragraphStyle" => [
"alignment" => "START"
],
"range" => [
"startIndex" => 5,
"endIndex" => 5,
],
"fields" => "alignment"
]]),
new Google_Service_Docs_Request([
"updateParagraphStyle" => [
"paragraphStyle" => [
"alignment" => "END"
],
"range" => [
"startIndex" => 8,
"endIndex" => 23,
],
"fields" => "alignment"
]]),
];
$batchUpdateRequest = new Google_Service_Docs_BatchUpdateDocumentRequest(array('requests' => $requests));
$responses = $service->documents->batchUpdate($documentId, $batchUpdateRequest);
From OP's following reply,
But as you see in my picture I have shown it in my header and from your script what I have to change to make it on my header and for your information I am able to get my header id. Just help me to modify your answer to place that table and image in my header.
Unfortunately, I couldn't notice you wanted to put it to the header from your question and your showing script. In this case, a simple modification is reflected in the above script. Please addsegmentId
to each request as follows.
$headerId = "kix.###"; // Please set your header ID.
$b = ["color" => ["color" => []], "dashStyle" => "SOLID", "width" => ["magnitude" => 0, "unit" => "PT"]];
$requests = [
new Google_Service_Docs_Request([
'insertTable' => [
'location' => ['index' => 1, "segmentId" => $headerId],
'columns' => 2,
'rows' => 1
]
]),
new Google_Service_Docs_Request([
"updateTableCellStyle" => [
"tableCellStyle" => [
"borderBottom" => $b,
"borderTop" => $b,
"borderLeft" => $b,
"borderRight" => $b,
],
"tableStartLocation" => ["index" => 2, "segmentId" => $headerId],
"fields" => "borderBottom,borderTop,borderLeft,borderRight"
]
]),
new Google_Service_Docs_Request([
"insertInlineImage" => [
"location" => ["index" => 5, "segmentId" => $headerId],
"uri" => "https://www.gstatic.com/images/branding/product/1x/docs_64dp.png",
"objectSize" => [
"height"=> [
"magnitude"=> 100,
"unit" => "PT"
],
"width"=> [
"magnitude"=> 100,
"unit"=> "PT"
]
]
]]),
new Google_Service_Docs_Request([
'insertText' => [
'text' => "hello1\nhello2\nhello3",
'location' => ['index' => 8, "segmentId" => $headerId]
]]),
new Google_Service_Docs_Request([
"updateParagraphStyle" => [
"paragraphStyle" => [
"alignment" => "START"
],
"range" => [
"startIndex" => 5,
"endIndex" => 5,
"segmentId" => $headerId
],
"fields" => "alignment"
]]),
new Google_Service_Docs_Request([
"updateParagraphStyle" => [
"paragraphStyle" => [
"alignment" => "END"
],
"range" => [
"startIndex" => 8,
"endIndex" => 23,
"segmentId" => $headerId
],
"fields" => "alignment"
]]),
];
$batchUpdateRequest = new Google_Service_Docs_BatchUpdateDocumentRequest(array('requests' => $requests));
$responses = $service->documents->batchUpdate($documentId, $batchUpdateRequest);
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.