2011-07-20 8 views
1

私の勘違いは次のとおりです。私はGoogle Docsのさまざまなスプレッドシートにたくさんのデータを保存しています。すべてのデータを単一のスプレッドシートにコンパイルすると(分析目的で)、サイズの上限に達します。それが出ているのを見て、別の方法が必要でした。PHPを使用して私のサイトに一連のGoogleドキュメント(.csvファイル)をダウンロード

私はAppsスクリプトを作成してデータを取得し、それを一連の対応する.csvファイルにエクスポートしました。私は今、Google Docsに保存されている30個の.csvファイルからデータを取得し、それをMySQLサーバーにインポートする必要があります。これは最も効率的な方法ですか?

今、私のGoogle Docs Listからサーバーにすべての.csvファイルをインポートする方法が必要です。ここでPHPスクリプトがデータベースにインポートできます。あなたは正しい方向に私を向けることができますか? ...

http://gdatatips.blogspot.com/2009/07/download-google-doc-using-php-library.html

function download($client, $url, $format=null) { 
    $sessionToken = $client->getHttpClient()->getAuthSubToken(); 
    $opts = array(
    'http' => array(
     'method' => 'GET', 
     'header' => "GData-Version: 3.0\r\n". 
        "Authorization: AuthSub token=\"$sessionToken\"\r\n" 
    ) 
); 
    if ($url != null) { 
    $url = $url . "&exportFormat=$format"; 
    } 
    return file_get_contents($url, false, stream_context_create($opts)); 
} 

// TODO 1: setup a Zend_Gdata_Docs client in $docs_client 
// TODO 2: fetch a $feed or $entry 
$contentLink = $feed->entries[0]->content->getSrc(); 
$fileContents = download($docs_client, $contentLink, 'txt'); 
echo 'Contents of document "' . $feed->entries[0]->title . '":<hr>'; 
echo "<pre>$fileContents</pre>"; 

感謝を

は、私はかなり近いようだ私の研究、中に以下の記事を発見したが、それは私の目的にそれを適応させることになると、それは残念ながら私の頭の上の方法ですとても!どんな支援も大歓迎です! :)

+0

のPHPのバージョンのようになりますように私には思えます単純なLOAD DATA LOCAL INFILE? –

+0

こんにちは@エドガー、コメントありがとう!残念なことに、これはタイムシートデータを追跡するシステムの一部であり、それぞれが30人の異なる人物を表し、常に更新されたデータがあります。私たちは理想的には、csvファイルをダウンロードする自動の方法、例えば1日1回のように思っています。最新の情報が利用可能であることを保証するため。これも可能ですか? – Andrew

答えて

0

スケジュールされたタスク(つまり1日に1回)から開始されたバッチファイルを使用して.csvファイルをダウンロードした後、バッチファイルでSQL c:\ sql \ update_timekeeping.sqlを開始します。 SQlコマンドは、update_timekeeping.sqlテキストファイルに格納されています。また、計時更新を実行しているの歴史を提供します....

+0

ありがとう@Gator!それは我々がやろうとしているように見える。ローカルマシン上のファイルをダウンロード/アップロードするジョブを設定する。みんなに助言をありがとう! – Andrew

0

あなたのサーバーに30CSVファイルをダウンロードしてやって考えがありfile_get_contents()このスクリプト

function file_get_contents(){ 
    //This function generates a pdf of your current spreadsheet and emails it to yourself as attachment 
    //Make sure your spreadsheet is not too big. The pdf size tends to be 200kb/page and if too large 
    //if the pdf is too large the urlFetch might timeout 

    var AUTH_TOKEN = "xxxxxxxxxxxxxx"; //Enter your AUTH_TOKEN 
    //You can receive it from https://appscripts.appspot.com/getAuthToken 

    var ssID=SpreadsheetApp.getActiveSpreadsheet().getId()+"&gid="+SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getSheetId(); 
    var url = "https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key=" 
     + ssID + "&exportFormat=csv"; 
    //Add &gid=x at the end of above url if you only want a particular sheet 
    //gid of a sheet can be obtained by the undocumented function getSheetId() 
    //ex: SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getSheetId(); 
    //exportFormat=xls did not work when I tried. I dont know why 

    var auth = "AuthSub token=\"" + AUTH_TOKEN + "\""; 

    var res = UrlFetchApp.fetch(url, {headers: {Authorization: auth}}); 
    var content=res.getContentText(); 
    return content 
} 
関連する問題