palx

gSheets to SQLite doesn't detect first row as column header

May 3rd, 2022 (edited)
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.48 KB | None | 0 0
  1. // https://morillasweb.com/index.php/2018/07/27/convert-google-sheet-to-sqlite/    
  2. // detect first row as column names if gSheet API doesn't
  3.  
  4.     $colNames = '';
  5.     foreach ($table->cols as $aCol) {
  6.         $colNames .= $aCol->label;
  7.     }
  8.     if ($colNames =='') {
  9.         $firstRow = array_shift($table->rows);
  10.         foreach ($table->cols as $key=>$aCol) {
  11.             $colNames .= $aCol->label;
  12.             $table->cols[$key]->label =  $firstRow->c[$key]->v;
  13.         }
  14.     }
Advertisement
Add Comment
Please, Sign In to add comment