Home > database >  How to read float value on width size?
How to read float value on width size?

Time:11-23

currently i need to set the width of column based on exported data. i found errors indicates that it cannot read float on width sizing.

   foreach($this->dataCols->all() as $columnName => $columnInfo)
{
                
                $width = floatval($columnInfo['width']) / 1;

                //width
                array_push($requests,
                new \Google\Service\Sheets\Request([
                    "updateDimensionProperties" => [
                        "range" => [
                            "sheetId" => $sheet_id,
                            "startIndex" => 0,
                            "endIndex" => (sizeof($this->dataCols->all())),
                            "dimension" => "COLUMNS",
                        ],
                        "properties" => ["pixelSize" => $width],
                        "fields" => "pixelSize",
                    ],
                ]),
            );

  }

Here is the error message:

"message": "Invalid value at 'requests[5].update_dimension_properties.properties.pixel_size' (TYPE_INT32), 2.3076923076923075

CodePudding user response:

From your error message of "message": "Invalid value at 'requests[5].update_dimension_properties.properties.pixel_size' (TYPE_INT32), 2.3076923076923075, it is considered that the reason for your current issue is due to the value of $width.

When we see the official document of DimensionProperties, the following document can be seen.

pixelSize: integer The height (if a row) or width (if a column) of the dimension in pixels.

From your error message, it seems that $width is 2.3076923076923075. I think that this is the reason for your issue. So, in this case, please modify this as the integer.

So, as a sample modification for testing your request, please modify as follows and test it again.

From:

"properties" => ["pixelSize" => $width],

To:

"properties" => ["pixelSize" => 200],
  • By this modification, I think that your script works without the error.

Note:

  • From your error message, I think that the value of 2.3076923076923075 is very small for the column width. For example, when $width is 2, it is difficult to see the cell value. Please be careful about this.

Reference:

  • Related