Class: GoogleSpreadsheet::Spreadsheet
- Inherits:
-
Object
- Object
- GoogleSpreadsheet::Spreadsheet
- Includes:
- Util
- Defined in:
- lib/google_spreadsheet.rb
Overview
Use methods in GoogleSpreadsheet::Session to get GoogleSpreadsheet::Spreadsheet object.
Instance Attribute Summary collapse
-
#title ⇒ Object
readonly
Title of the spreadsheet.
-
#worksheets_feed_url ⇒ Object
readonly
URL of worksheet-based feed of the spreadsheet.
Instance Method Summary collapse
-
#add_worksheet(title, max_rows = 100, max_cols = 20) ⇒ Object
Adds a new worksheet to the spreadsheet.
-
#initialize(session, worksheets_feed_url, title = nil) ⇒ Spreadsheet
constructor
:nodoc:.
-
#worksheets ⇒ Object
Returns worksheets of the spreadsheet as array of GoogleSpreadsheet::Worksheet.
Methods included from Util
encode_query, h, http_request, uri_encode
Constructor Details
#initialize(session, worksheets_feed_url, title = nil) ⇒ Spreadsheet
:nodoc:
240 241 242 243 244 |
# File 'lib/google_spreadsheet.rb', line 240 def initialize(session, worksheets_feed_url, title = nil) #:nodoc: @session = session @worksheets_feed_url = worksheets_feed_url @title = title end |
Instance Attribute Details
#title ⇒ Object (readonly)
Title of the spreadsheet. So far only available if you get this object by GoogleSpreadsheet::Session#spreadsheets.
251 252 253 |
# File 'lib/google_spreadsheet.rb', line 251 def title @title end |
#worksheets_feed_url ⇒ Object (readonly)
URL of worksheet-based feed of the spreadsheet.
247 248 249 |
# File 'lib/google_spreadsheet.rb', line 247 def worksheets_feed_url @worksheets_feed_url end |
Instance Method Details
#add_worksheet(title, max_rows = 100, max_cols = 20) ⇒ Object
Adds a new worksheet to the spreadsheet. Returns added GoogleSpreadsheet::Worksheet.
267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
# File 'lib/google_spreadsheet.rb', line 267 def add_worksheet(title, max_rows = 100, max_cols = 20) xml = " <entry xmlns='http://www.w3.org/2005/Atom'\n xmlns:gs='http://schemas.google.com/spreadsheets/2006'>\n <title>\#{h(title)}</title>\n <gs:rowCount>\#{h(max_rows)}</gs:rowCount>\n <gs:colCount>\#{h(max_cols)}</gs:colCount>\n </entry>\n EOS\n doc = @session.post(@worksheets_feed_url, xml)\n url = doc.search(\n \"link[@rel='http://schemas.google.com/spreadsheets/2006#cellsfeed']\")[0][\"href\"]\n return Worksheet.new(@session, url, title)\nend\n" |
#worksheets ⇒ Object
Returns worksheets of the spreadsheet as array of GoogleSpreadsheet::Worksheet.
254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/google_spreadsheet.rb', line 254 def worksheets doc = @session.get(@worksheets_feed_url) result = [] for entry in doc.search("entry") title = entry.search("title").text url = entry.search( "link[@rel='http://schemas.google.com/spreadsheets/2006#cellsfeed']")[0]["href"] result.push(Worksheet.new(@session, url, title)) end return result.freeze() end |