首页 > 解决方案 > 更新工作表值时 Google Sheet API 更改列格式

问题描述

我可以使用以下代码来更新工作表值。

// 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);

}

我有大约 78 列数据。其中一些只是纯文本。其中一些是数字。

我用这些数据创建数据透视表。所以我需要将数字正确格式化为数字。似乎当我更新数据时,格式被删除了。数字未格式化为数字。

我如何能够编写数据并告诉 Google 表格将数字格式化为实际数字?这些是我的专栏。

        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"

         ];

标签: google-sheets-api

解决方案


推荐阅读