Laravel 到 Google Sheets 的新行不从开头开始。

huangapple go评论56阅读模式
英文:

Laravel to Google Sheets new lines not starting at beginning

问题

I'm using this package to store data from a Laravel app into Google Sheets: https://github.com/kawax/laravel-google-sheets/

Everything works fine except for one strange issue. Here's how I add new lines to the sheet:

$sheet = Sheets::spreadsheet("sheet_name")->sheet("tab_name");
$sheet->append($this->data);

$this->data contains an associative array with the column names and values.

Most of the times the new lines are added as desired. But sometimes they start in column B with everything shifted over. And now today they are randomly starting in column V.

I can see that the last line in that sheet has values up to column U, so there must be a connection, even though this new line is added five lines lower.

I've not been able to specify a range for the append method. Is there a way to force Google Sheets to store the data starting from A?

英文:

I'm using this package to store data from a Laravel app into Google Sheets: https://github.com/kawax/laravel-google-sheets/

Everything works fine except for one strange issue. Here's how I add new lines to the sheet:

$sheet = Sheets::spreadsheet("sheet_name")->sheet("tab_name");
$sheet->append($this->data);

$this->data contains an associative array with the column names and values.

Most of the times the new lines are added as desired. But sometimes they start in column B with everything shifted over. And now today they are randomly starting in column V.

I can see that the last line in that sheet has values up to column U, so there must be a connection, even though this new line is added five lines lower.

I've not been able to specify a range for the append method. Is there a way to force Google Sheets to store the data starting from A?

答案1

得分: 1

如果有人偶然发现这个,我终于找到了答案。问题似乎是光标或范围在请求之间没有重置,因此输入位置可以根据上次请求的结束位置而变化。解决方案是以这种方式重置范围:

$sheet->range('')->append($this->data);
英文:

If anybody stumbles across this, I finally found the answer. The issue seems to be that the cursor or range isn't reset between requests, so the input position can change depending on where the last request left off. The solution was to reset the range in such a way:

$sheet->range('')->append($this->data);

huangapple
  • 本文由 发表于 2023年2月18日 20:24:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/75493315.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定