asimlqt / php-google-spreadsheet-client

A PHP library for accessing and manipulating Google Spreadsheets
Other
544 stars 152 forks source link

Reverse Option Being Ignored? #104

Closed BT643 closed 8 years ago

BT643 commented 9 years ago

Is anyone else having issues trying to get spreadsheets in reverse order (ie - row 100 down to row 1).

 $worksheet = $spreadsheet->getWorksheets()->getByTitle('Sheet1');
 $listFeed = $worksheet->getListFeed(array("reverse" => "true"));

I have my code like that, but with "reverse" set to "true" or "false" the results I get are identical (results come through fine, but they appear the order they are in the Google Sheets web UI. I need them in reverse order.

Not sure why the reverse option is not working.

Any ideas?

asimlqt commented 9 years ago

Hello BT643,

Yes you're right, Google doesn't seem to be honoring the "reverse" parameter.

I've tried "orderby" and that works e.g.

$listFeed = $worksheet->getListFeed(array("orderby" => "column:name"));

Or you can just do an array_reverse when looping over the results e.g.

foreach(array_reverse($listFeed->getEntries()) as $entry) {
    // $entry->getValues();
}