Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Parse Google Spreadsheets (https://forums.graalonline.com/forums/showthread.php?t=134259850)

cbk1994 07-16-2010 12:22 AM

Parse Google Spreadsheets
 
1 Attachment(s)
I wasn't planning on posting this as it's very simple but someone requested it, and it can be very useful :).

This simple script will load a Google Docs spreadsheet and turn it into an array of rows/columns.

PHP Code:

public function parseSpreadsheet(url) {
  
temp.req requestURL(url);
  
waitfor(req"onReceiveData"30);
  
  
temp.rows null;
  
temp.lines req.data;
  
  for (
temp.line lines) {
    
temp.row null;
    
    for (
temp.column line.tokenize(char(9))) {
      
row.add(column);
    }
    
    
rows.add(row);
  }
  
  return 
rows;


To get the URL needed, from the Google Spreadsheet choose "Share" then "Publish as web page" at the top-right. Click "Start publishing" and optionally click "Automatically republish as I make changes". Then, from the drop-down list for "Get the link to share", choose "TXT (Plain text)" and copy the link given.

http://img411.imageshack.us/img411/5719/fixt.png

Example usage:
PHP Code:

function onCreated() {
  
temp.url "my_url";
  
temp.rows parseSpreadsheet(url);
  
  for (
temp.row rows) {
   echo(
row);
  }


I'm sure you can think up plenty of uses for this. The one I'm currently using it for on Era is a translation table—the spreadsheet is cached into a script-friendly file which is sent to players on login and can be used for translating text.
Attachment 51383

adam 07-16-2010 01:22 AM

Excellent work.

xAndrewx 07-16-2010 10:37 AM

Thank you =D

I think this should be added on Login truth be told, great job and thanks for posting :) (I'd REP but I've repped you already :()


All times are GMT +2. The time now is 12:04 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.