问题
I can use the following code to update sheet values.
// Initilize client
$this->client = new \Google_Client();
$this->client->setApplicationName('My App');
$this->client->setScopes([\Google_Service_Sheets::SPREADSHEETS]);
$this->client->setAccessType('offline');
$this->client->setAuthConfig("$authJSONFile");
$body = new Google_Service_Sheets_ValueRange([
'values' => $valuesArray
]);
$params = [
'valueInputOption' => 'RAW'
];
try {
$updateSheet = $this->sheets->spreadsheets_values->update($this->sheetID, $updateRange, $body, $params);
return $updateSheet;
} catch (Exception $e) {
trigger_error($e);
}
I have around 78 columns of data. Some of it is just plain text. Some of it is numbers.
I create pivot tables with this data. So I need numbers to be properly formatted as numbers. It seems when I update data the formatting is deleted. Numbers are not formatted as numbers.
How would I be able to write data and tell Google Sheets to format numbers as actual numbers? These are my columns.
public $FBDataColumns = [
"business_manager_name",
"account_name",
"campaign_name",
"adset_name",
"ad_name",
"delivery_status",
"objective",
"impressions",
"reach",
"budget",
"bid_strategy",
"age",
"gender",
"country",
"region",
"platform",
"placement",
"device",
"time_of_day",
"amount_spent",
"atc_value",
"initiate_checkout_value",
"purchase_value",
"estimated_profit",
"purchase_ROAS",
"cpm",
"click_through_rate_all",
"cost_per_click_all",
"click_through_rate_link",
"cost_per_link_click",
"cost_per_landing_page_view",
"cost_per_view_content",
"cost_per_add_to_cart",
"cost_per_initiate_checkout",
"cost_per_purchase",
"total_video_views",
"video_views_25%_watched",
"video_views_50%_watched",
"video_views_75%_watched",
"video_views_95%_watched",
"video_views_100%_watched",
"average_watch_time",
"link_clicks",
"landing_page_views",
"view_content",
"add_to_cart",
"initiate_checkout",
"purchases",
"conversion_rate_ranking",
"engagement_rate_ranking",
"quality_ranking",
"quality_ranking_extra",
"frequency",
"unique_click_through_rate_all",
"unique_cost_per_click_all",
"unique_click_through_rate_link",
"unique_cost_per_link_click",
"unique_cost_per_landing_page_view",
"unique_cost_per_view_content",
"unique_cost_per_add_to_cart",
"unique_cost_per_initiate_checkout",
"unique_cost_per_purchase",
"unique_landing_page_view",
"unique_view_contents",
"unique_add_to_carts",
"unique_initiate_checkouts",
"unique_purchases",
"post_engagement",
"page_engagement",
"post_reaction",
"post_comment",
"post_saves",
"business_manager_id",
"account_id",
"campaign_id",
"adset_id",
"ad_id",
"ad_date_start",
"ad_date_stop"
];
来源:https://stackoverflow.com/questions/64886023/google-sheet-api-change-column-formatting-when-updating-sheet-values