Exemple #1
0
function gdata_import($attrib)
{
    if ($attrib["key"] == "" || $attrib["worksheet"] == "" || $attrib["user"] == "" || $attrib["pass"] == "") {
        echo 'ERROR: SET ALL ATTRIBUTES i.e sheet, worksheet, user, pass and columns. ';
        return;
    }
    // load Zend Gdata libraries
    set_include_path(get_include_path() . PATH_SEPARATOR . WP_PLUGIN_DIR . "//gdata-importer//");
    require_once 'Zend/Loader.php';
    Zend_Loader::loadClass('Zend_Gdata_Spreadsheets');
    Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
    // set credentials for ClientLogin authentication
    $user = $attrib["user"];
    $pass = $attrib["pass"];
    try {
        // connect to API
        $service = Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME;
        $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
        $service = new Zend_Gdata_Spreadsheets($client);
        // get spreadsheet entry
        $ssEntry = $service->getSpreadsheetEntry('https://spreadsheets.google.com/feeds/spreadsheets/' . $attrib["key"]);
        // get worksheets in this spreadsheet
        $wsFeed = $ssEntry->getWorksheets($attrib["worksheet"]);
    } catch (Exception $e) {
        echo 'ERROR: ' . $e->getMessage();
        return;
    }
    $content = <<<HTML
\t<table>
HTML;
    foreach ($wsFeed as $wsEntry) {
        if ($wsEntry->getTitle() == $attrib["worksheet"]) {
            //get title
            $query = new Zend_Gdata_Spreadsheets_CellQuery();
            $query->setSpreadsheetKey($attrib["key"]);
            $id = $wsEntry->getId();
            $arr = explode('/', $id);
            $query->setWorksheetId($arr[sizeof($arr) - 1]);
            $query->setMinRow(1);
            $query->setMaxRow(1);
            $cellFeed = $service->getCellFeed($query);
            $content = $content . "<tr>";
            foreach ($cellFeed as $cellEntry) {
                $content = $content . "<td>" . $cellEntry->getCell()->getText() . "</td>";
            }
            $content = $content . "</tr>";
            //get content
            $rows = $wsEntry->getContentsAsRows();
            foreach ($rows as $row) {
                $content = $content . "<tr>";
                foreach ($row as $key => $value) {
                    $content = $content . "<td>" . $value . "</td>";
                }
                $content = $content . "</tr>";
            }
        }
    }
    $content = $content . <<<HTML
\t\t</tbody>
\t</table>
HTML;
    return $content;
}
Exemple #2
0
 * @see Zend_Gdata_ClientLogin
 */
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
/**
 * @see Zend_Gdata_Spreadsheets
 */
Zend_Loader::loadClass('Zend_Gdata_Spreadsheets');
$authService = Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME;
$httpClient = Zend_Gdata_ClientLogin::getHttpClient('*****@*****.**', 'internet21', $authService);
$gdClient = new Zend_Gdata_Spreadsheets($httpClient);
$query = new Zend_Gdata_Spreadsheets_CellQuery();
$query->setSpreadsheetKey('0AlkFQsJI6D_7dEZOVXlTeDNYOGsyNVNWalNLdWdDU2c');
$query->setWorksheetId(3);
$query->setMinCol(3);
$query->setMaxCol(3);
$query->setMinRow(17);
$query->setMaxRow(17);
$feed = $gdClient->getCellFeed($query);
$entry = $gdClient->updateCell(16, 4, $_GET['precio'], '0AlkFQsJI6D_7dEZOVXlTeDNYOGsyNVNWalNLdWdDU2c', 3);
$entry = $gdClient->updateCell(17, 4, $_GET['enganche'], '0AlkFQsJI6D_7dEZOVXlTeDNYOGsyNVNWalNLdWdDU2c', 3);
$entry = $gdClient->updateCell(13, 9, $_GET['anio'], '0AlkFQsJI6D_7dEZOVXlTeDNYOGsyNVNWalNLdWdDU2c', 3);
$entry = $gdClient->updateCell(13, 3, $_GET['marca'], '0AlkFQsJI6D_7dEZOVXlTeDNYOGsyNVNWalNLdWdDU2c', 3);
$entry = $gdClient->updateCell(14, 3, $_GET['linea'], '0AlkFQsJI6D_7dEZOVXlTeDNYOGsyNVNWalNLdWdDU2c', 3);
$i = 0;
foreach ($feed->entries as $entry) {
    if ($entry instanceof Zend_Gdata_Spreadsheets_CellEntry) {
        print "<div class=\"calc-item\"><label>Monto del enganche:</label> " . number_format($entry->content->text, 2) . "</div>";
    }
    $i++;
}
$query->setMinCol(5);
Exemple #3
0
 function displayWorksheetData($spreedSheetId, $worksheetId)
 {
     $query = new Zend_Gdata_Spreadsheets_CellQuery();
     $query->setSpreadsheetKey($spreedSheetId);
     $query->setWorksheetId($worksheetId);
     $query->setMinRow(4);
     $cellFeed = $this->client->getCellFeed($query);
     $i = 1;
     $row_previous_value = 0;
     foreach ($cellFeed as $cellEntry) {
         $column = intval($cellEntry->cell->getColumn());
         $row = intval($cellEntry->cell->getRow());
         if ($row_previous_value != $row) {
             $i = 1;
             $row_previous_value = $row;
         }
         while ($column != $i) {
             $data[$row][$i] = '';
             $i++;
         }
         $data[$row][$column] = $cellEntry->cell->getText();
         $i++;
     }
     return $data;
 }