Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #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
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 06:26 AM.


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