View Single Post
  #1  
Old 07-16-2010, 12:22 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Parse Google Spreadsheets

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.



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.
Click image for larger version

Name:	Capture 2010-07-15 at 6.20.23 PM.png
Views:	291
Size:	95.7 KB
ID:	51383
__________________
Reply With Quote