I'm creating a Google Sheet adding content like: =HYPERLINK("https://example.com","Example")
Which works fine until I try to alter the cell -> userEnteredFormat -> textFormat
Here's an example of broken links
Cell formatting works (see the second sheet).
If I change my config from
"cell" => [
"userEnteredFormat" => [
"backgroundColor" => [
"red" => 1.0,
"green" => 1.0,
"blue" => 1.0
],
"horizontalAlignment" => "LEFT",
"wrapStrategy" => "WRAP",
"textFormat" => [
"foregroundColor" => [
"red" => 0.0,
"green" => 0.0,
"blue" => 0.5
],
"fontSize" => 10,
"bold" => true
]
]
],
"fields" => "userEnteredFormat(backgroundColor,textFormat,horizontalAlignment,wrapStrategy)"
To
"cell" => [
"userEnteredFormat" => [
"backgroundColor" => [
"red" => 1.0,
"green" => 1.0,
"blue" => 1.0
],
"horizontalAlignment" => "LEFT",
"wrapStrategy" => "WRAP",
"textFormat" => [
]
]
],
"fields" => "userEnteredFormat(backgroundColor,textFormat,horizontalAlignment,wrapStrategy)"
The issue goes away.
I thought that from your request body, I thought that the reason of your issue might be due to fields. So, in your situation, how about modifying the value of fields as follows?
From:
"fields" => "userEnteredFormat(backgroundColor,textFormat,horizontalAlignment,wrapStrategy)"
To:
"fields" => "userEnteredFormat(backgroundColor,textFormat(foregroundColor,fontSize,bold),horizontalAlignment,wrapStrategy)"
Reference:
Method: spreadsheets.batchUpdate
Related
the following is a batch updates request, it is styling only the sheet of index 0, I would like to apply this style to all sheets in the spreadsheet, or alternatively style each sheet by name...
I am trying to avoid making a request, getting the sheet ids and names, and styling each one by its id.
// start sheet formatting for better readability/visuals
$formatRowColrequests = [
new \Google\Service\Sheets\Request([
'updateSheetProperties' => [
'properties' => [
'gridProperties' => [
'frozenRowCount' => 1
]
],
'fields' => 'gridProperties.frozenRowCount'
]
]),
// columns auto width to fit content
new \Google\Service\Sheets\Request([
"autoResizeDimensions" => [
"dimensions" => [
"dimension" => "COLUMNS",
"startIndex" => 0,
]
]
]),
new \Google\Service\Sheets\Request([
"repeatCell" => [
"range" => [
"endRowIndex" => 1,
],
"cell" => [
"userEnteredFormat" => [
"backgroundColor" => [
"red" => 152 / 255,
"green" => 217 / 255,
"blue" => 99 / 255,
"alpha" => 0.8
],
"horizontalAlignment" => "LEFT",
"textFormat" => [
"fontSize" => 12,
"bold" => true,
]
]
],
"fields" => "userEnteredFormat(textFormat,backgroundColor,horizontalAlignment)"
]
]),
new \Google\Service\Sheets\Request([
"repeatCell" => [
"range" => [
"startRowIndex" => 1,
],
"cell" => [
"userEnteredFormat" => [
"horizontalAlignment" => "LEFT",
"textFormat" => [
"fontSize" => 10,
"bold" => false
]
]
],
"fields" => "userEnteredFormat(textFormat,backgroundColor,horizontalAlignment)"
],
]),
];
$batchUpdateCellFormatRequest = new \Google\Service\Sheets\BatchUpdateSpreadsheetRequest([
'requests' => $formatRowColrequests,
]);
$service->spreadsheets->batchUpdate($target_spreadID, $batchUpdateCellFormatRequest);
// end sheet formatting
```
I believe your goal is as follows.
You want to use your request body for all sheets or the specific sheets using the sheet names.
You want to achieve this using googleapis for PHP.
You have already been able to get and put values to the Spreadsheet using Sheets API.
In this case, how about the following modification? In this modification, first, the sheet IDs are retrieved using the sheet names. Using these sheet IDs, your request body is used for the specification sheets.
Modified script:
$target_spreadID = "###"; // please set Spreadsheet ID.
// Retrieve sheet IDs.
$sheetNames = ["Sheet1", "Sheet3"]; // Please set the sheet names you want to use the request body.
$res = $service->spreadsheets->get($target_spreadID, [
"ranges" => $sheetNames,
"fields" => "sheets(properties(sheetId))",
]);
// Create request body.
$sheets = $res->getSheets();
$requests = [];
foreach ($sheets as $i => $sheet) {
$sheetId = $sheet->getProperties()->getSheetId();
$formatRowColrequests = [
new \Google\Service\Sheets\Request([
"updateSheetProperties" => [
"properties" => [
"gridProperties" => [
"frozenRowCount" => 1,
],
"sheetId" => $sheetId,
],
"fields" => "gridProperties.frozenRowCount",
],
]),
// columns auto width to fit content
new \Google\Service\Sheets\Request([
"autoResizeDimensions" => [
"dimensions" => [
"dimension" => "COLUMNS",
"startIndex" => 0,
"sheetId" => $sheetId,
],
],
]),
new \Google\Service\Sheets\Request([
"repeatCell" => [
"range" => [
"endRowIndex" => 1,
"sheetId" => $sheetId,
],
"cell" => [
"userEnteredFormat" => [
"backgroundColor" => [
"red" => 152 / 255,
"green" => 217 / 255,
"blue" => 99 / 255,
"alpha" => 0.8,
],
"horizontalAlignment" => "LEFT",
"textFormat" => [
"fontSize" => 12,
"bold" => true,
],
],
],
"fields" =>
"userEnteredFormat(textFormat,backgroundColor,horizontalAlignment)",
],
]),
new \Google\Service\Sheets\Request([
"repeatCell" => [
"range" => [
"startRowIndex" => 1,
"sheetId" => $sheetId,
],
"cell" => [
"userEnteredFormat" => [
"horizontalAlignment" => "LEFT",
"textFormat" => [
"fontSize" => 10,
"bold" => false,
],
],
],
"fields" =>
"userEnteredFormat(textFormat,backgroundColor,horizontalAlignment)",
],
]),
];
$requests = array_merge($requests, $formatRowColrequests);
}
$batchUpdateCellFormatRequest = new \Google\Service\Sheets\BatchUpdateSpreadsheetRequest(["requests" => $requests]);
// Request Sheets API using the created request body.
$service->spreadsheets->batchUpdate($target_spreadID, $batchUpdateCellFormatRequest);
When this script is run, your request body is used for the specific sheets declared by $sheetNames = ["Sheet1", "Sheet3"];.
If you want to use your request body to all sheets in the Spreadsheet, please modify the above script as follows.
From
$sheetNames = ["Sheet1", "Sheet3"]; // Please set the sheet names you want to use the request body.
$res = $service->spreadsheets->get($target_spreadID, [
"ranges" => $sheetNames,
"fields" => "sheets(properties(sheetId))",
]);
To
$res = $service->spreadsheets->get($target_spreadID, [
"fields" => "sheets(properties(sheetId))",
]);
References:
Method: spreadsheets.get
Method: spreadsheets.batchUpdate
I am working on google docs api with PHP code. I want to insert an image and texts in same line.Is it possible to do this with google docs api?
I can insert image and texts but not in single line.Is there any way to do so?
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?
Sample script:
$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);
When this script is run, a table of 1 row and 2 columns is created and the table border is removed. And, the image and text are put to the columns "A" and "B", respectively. And then, each cell is aligned.
Note:
In this sample, I used a table of 1 row and 2 columns. If you want to modify this alignment, please modify the above script for your actual situation.
Added:
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 add segmentId to each request as follows.
Sample script:
$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);
Note:
If you use the header ID of the 1st header ID, please check the checkbox for using the 1st header on the Google Document.
I have been trying to create a MediaConverter job using the latest AWS SDK for PHP (7.4.2) and I'm getting really stuck at creating the job settings correctly. I was wondering if anyone could look at this php code and tell me if I'm just completely on the wrong track. The response I'm getting is:
Error executing "CreateJob" on "https://asdf.mediaconvert.us-east-1.amazonaws.com/2017-08-29/jobs"; AWS HTTP error: Client error: POST https://asdf.mediaconvert.us-east-1.amazonaws.com/2017-08-29/jobs resulted in a 400 Bad Request response: { "errorType": "BadRequestException", "httpStatus" : 400, "requestId" : "388473f1-92af-4253-940c-00307b7c2a79", (truncated...) BadRequestException (client): The request could not be interpreted. - { "errorType": "BadRequestException", "httpStatus" : 400, "requestId" : "388473f1-92af-4253-940c-00307b7c2a79", "message" : "The request could not be interpreted.", "settingsValidationErrorsJsonBlob" : "" }
I actually copied the JSON for the settings directly out of MediaConvert, so I assume that my issue lies in trying to convert this into an object in PHP for the purposes of sending it to AWS. The settings below make it through the AWS SDK and up to the server, which I suppose is a good start. But I can't figure out what is wrong.
"OutputGroups" => [
[
"CustomName" => "Thumbnails",
"Name" => "File Group",
"Outputs" => [
"ContainerSettings" => [
"Container" => "RAW"
],
"VideoDescription" => [
"Width" => 1280,
"ScalingBehavior" => "DEFAULT",
"Height" => 720,
"TimecodeInsertion" => "DISABLED",
"AntiAlias" => "ENABLED",
"Sharpness" => 50,
"CodecSettings" => [
"Codec" => "FRAME_CAPTURE",
"FrameCaptureSettings" => [
"FramerateNumerator" => 30,
"FramerateDenominator" => 540,
"MaxCaptures" => 18,
"Quality" => 70
]
],
"DropFrameTimecode" => "ENABLED",
"ColorMetadata" => "INSERT"
],
["Extension" => "jpg"],
["NameModifier" => "-thumb"]
],
"OutputGroupSettings" => [
"Type" => "FILE_GROUP_SETTINGS",
"FileGroupSettings" => [
"Destination" => "s3://me/my-folder/"
]
]
],
[
"CustomName" => "720p",
"Name" => "File Group",
"Outputs" => [
"ContainerSettings" => [
"Container" => "MP4",
"Mp4Settings" => [
"CslgAtom" => "INCLUDE",
"CttsVersion" => 0,
"FreeSpaceBox" => "EXCLUDE",
"MoovPlacement" => "PROGRESSIVE_DOWNLOAD"
]
],
"VideoDescription" => [
"Width" => 1280,
"ScalingBehavior" => "DEFAULT",
"Height" => 720,
"VideoPreprocessors" => [
"ImageInserter" => [
"InsertableImages" => [
"Width" => 200,
"Height" => 36,
"imageX" => 50,
"imageY" => 634,
"FadeIn" => 2000,
"Layer" => 2,
"ImageInserterInput" => "s3://me-again/My-Watermark.tga",
"StartTime" => "00:00:05;01",
"Opacity" => 50
]
]
],
"TimecodeInsertion" => "DISABLED",
"AntiAlias" => "ENABLED",
"Sharpness" => 50,
"CodecSettings" => [
"Codec" => "H_264",
"H264Settings" => [
"InterlaceMode" => "PROGRESSIVE",
"NumberReferenceFrames" => 3,
"Syntax" => "DEFAULT",
"Softness" => 0,
"GopClosedCadence" => 1,
"GopSize" => 90,
"Slices" => 1,
"GopBReference" => "DISABLED",
"SlowPal" => "DISABLED",
"SpatialAdaptiveQuantization" => "ENABLED",
"TemporalAdaptiveQuantization" => "ENABLED",
"FlickerAdaptiveQuantization" => "DISABLED",
"EntropyEncoding" => "CABAC",
"Bitrate" => 1800000,
"FramerateControl" => "INITIALIZE_FROM_SOURCE",
"RateControlMode" => "CBR",
"CodecProfile" => "MAIN",
"Telecine" => "NONE",
"MinIInterval" => 0,
"AdaptiveQuantization" => "HIGH",
"CodecLevel" => "AUTO",
"FieldEncoding" => "PAFF",
"SceneChangeDetect" => "ENABLED",
"QualityTuningLevel" => "SINGLE_PASS",
"FramerateConversionAlgorithm" => "DUPLICATE_DROP",
"UnregisteredSeiTimecode" => "DISABLED",
"GopSizeUnits" => "FRAMES",
"ParControl" => "INITIALIZE_FROM_SOURCE",
"NumberBFramesBetweenReferenceFrames" => 2,
"RepeatPps" => "DISABLED",
"DynamicSubGop" => "STATIC"
]
],
"AfdSignaling" => "NONE",
"DropFrameTimecode" => "ENABLED",
"RespondToAfd" => "NONE",
"ColorMetadata" => "INSERT"
],
"AudioDescriptions" => [
"AudioTypeControl" => "FOLLOW_INPUT",
"AudioSourceName" => "Audio Selector 1",
"CodecSettings" => [
"Codec" => "AAC",
"AacSettings" => [
"AudioDescriptionBroadcasterMix" => "NORMAL",
"Bitrate" => 96000,
"RateControlMode" => "CBR",
"CodecProfile" => "LC",
"CodingMode" => "CODING_MODE_2_0",
"RawFormat" => "NONE",
"SampleRate" => 48000,
"Specification" => "MPEG4"
]
],
"LanguageCodeControl" => "FOLLOW_INPUT"
],
["Extension" => "mp4"],
["NameModifier" => "-720p"]
],
"OutputGroupSettings" => [
"Type" => "FILE_GROUP_SETTINGS",
"FileGroupSettings" => [
"Destination" => "s3://me/my-folder"
]
]
]
],
"AdAvailOffset" => 0,
"Inputs" => [
[
"AudioSelectors" => [
"Audio Selector 1" => [
"Offset" => 0,
"DefaultSelection" => "DEFAULT",
"ProgramSelection" => 1
]
],
"FilterEnable" => "AUTO",
"PsiControl" => "USE_PSI",
"FilterStrength" => 0,
"DeblockFilter" => "DISABLED",
"DenoiseFilter" => "DISABLED",
"TimecodeSource" => "EMBEDDED",
"FileInput" => "s3://me-again/my-folder/my-video.mp4"
]
],
"AccelerationSettings" => [
"Mode" => "DISABLED"
],
"StatusUpdateInterval" => "SECONDS_60",
"Priority" => 0
];```
I solved this.
I took the JSON that I got from MediaConvert and then I created my PHP in five steps:
Replace all { with array(
Replace all : with =>
Replace all [ with array(
Replace all } with )
Replace all ] with )
After doing this it worked perfectly, first time.
Trying to make REST API skype bot but have a problem with a suggested actions message.
I prepare JSON with code like this:
$message = [
"type" => "message",
"from" => [
"id" => $clientid,
],
"conversation" => [
"id" => $chatid,
],
"recipient" => [
"id" => $chatid,
],
"text" => "Color",
"inputHint" => "expectingInput",
"suggestedActions" => [
"to" => [ $reptoid ],
"actions" => [
[
"type" => "imBack",
"title" => "Blue",
"value" => "Blue"
],
[
"type" => "imBack",
"title" => "Green",
"value" => "Green"
],
],
],
"replyToId" => $replyid
];
And after I send - I get in skype only text, wihout any buttons.
What I'm doing wring?
Based on the Channel Inspector, it seems that Suggested Actions in Skype are only available in the context of Cards.
Using elasticsearch I try find all items by word "skiing".
My mapping (PHP array):
"properties" => [
"title" => [
"type" => "string",
"boost" => 1.0,
"analyzer" => "autocomplete"
]
]
Settings:
"settings"=> [
"analysis" => [
"analyzer" => [
"autocomplete" => [
"type" => "custom",
"tokenizer" => "standard",
"filter" => ["lowercase", "trim", "synonym", "porter_stem"],
"char_filter" => ["html_strip"]
]
],
"filter" => [
"synonym" => [
"type" => "synonym",
"synonyms_path" => "analysis/synonyms.txt"
]
]
]
]
Search query:
[
"index" => "articles",
"body" => [
"query" => [
"filtered" => [
"query" => [
"bool" => [
"must" => [
"indices" => [
"indices" => ["articles"],
"query" => [
"bool" => [
"should" => [
"multi_match" => [
"query" => "skiing",
"fields" => ["title"]
]
]
]
]
]
]
]
]
]
],
"sort" => [
"_score" => [
"order" => "desc"
]
]
],
"size" => 10,
"from" => 0,
"search_type" => "dfs_query_then_fetch",
"explain" => true
];
In the sysnonyms.txt have skiing => xanthic.
I want get all items with "skiing" (because it is input word), "ski" (by porter_stem tokenizer) and then "xanthic" (by synonyms file). But get result only with word "xanthic".
Please, tell me why? How I need configure the index?
In the synonyms file you need to have "skiing, xanthic". In the way you have it now you are replacing skiing with xanthic, but you want to keep both. And I think you need to reindex the data to see the change.
Thanx, but this is decision. I changed mapping:
"properties" => [
"title" => [
"type" => "string",
"boost" => 1.5,
"analyzer" => "standard",
"fields" => [
"english" => [
"type" => "string",
"analyzer" => "standard",
"search_analyzer" => "english",
"boost" => 1.0
],
"synonym" => [
"type" => "string",
"analyzer" => "standard",
"search_analyzer" => "synonym",
"boost" => 0.5
]
]
]
]
Settings:
"settings"=> [
"analysis" => [
"analyzer" => [
"synonym" => [
"type" => "custom",
"tokenizer" => "standard",
"filter" => ["lowercase", "trim", "synonym"],
"char_filter" => ["html_strip"]
]
],
"filter" => [
"synonym" => [
"type" => "synonym",
"synonyms_path" => "analysis/synonyms.txt"
]
]
]
]