spreadsheet

package module
v0.0.0-...-5c0ab27 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2016 License: MIT Imports: 9 Imported by: 0

README

spreadsheet

Build Status Coverage Status GoReport GoDoc License Project Status

Package spreadsheet provides access to the Google Sheets API for reading and updating spreadsheets.

Any pull-request is welcome.

Example

package main

import (
	"fmt"
	"io/ioutil"

	"github.com/Iwark/spreadsheet"
	"golang.org/x/net/context"
	"golang.org/x/oauth2/google"
)

func main() {
	data, _ := ioutil.ReadFile("client_secret.json")
	conf, _ := google.JWTConfigFromJSON(data, spreadsheet.Scope)
	client := conf.Client(context.TODO())

	service := &spreadsheet.Service{Client: client}
	sheets, _ := service.Get("1mYiA2T4_QTFUkAXk0BE3u7snN2o5FgSRqxmRrn_Dzh4")
	ws, _ := sheets.Get(0)
	for _, row := range ws.Rows {
		for _, cell := range row {
			fmt.Println(cell.Content)
		}
	}

	// Update cell content
	ws.Rows[0][0].Update("hogehoge")

	// Make sure call Synchronize to reflect the changes
	ws.Synchronize()
}

License

Spreadsheet is released under the MIT License.

Documentation

Overview

Package spreadsheet provides access to the Google Sheets API for reading and updating spreadsheets.

Usage example:

import "github.com/Iwark/spreadsheet"
...
service := &spreadsheet.Spreadsheet{Client: oauthHTTPClient}

Index

Constants

View Source
const (

	// Scope is the API scope for viewing and managing your Google Spreadsheet data.
	// Useful for generating JWT values.
	Scope = "https://spreadsheets.google.com/feeds"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cell

type Cell struct {
	ID      string    `xml:"id"`
	Updated time.Time `xml:"updated"`
	Title   string    `xml:"title"`
	Content string    `xml:"content"`
	Links   []link    `xml:"link"`
	Pos     struct {
		Row int `xml:"row,attr"`
		Col int `xml:"col,attr"`
	} `xml:"cell"`
	// contains filtered or unexported fields
}

A Cell represents an individual cell in a worksheet.

func (*Cell) FastUpdate

func (c *Cell) FastUpdate(content string)

FastUpdate updates the content of the cell and appends the cell to the list of modified cells.

func (*Cell) Update

func (c *Cell) Update(content string)

Update will update the content of the cell.

type Cells

type Cells struct {
	XMLName xml.Name `xml:"feed"`
	Title   string   `xml:"title"`
	Entries []*Cell  `xml:"entry"`
}

Cells represents a group of cells.

type Service

type Service struct {
	// BaseURL is the base URL used for making API requests.
	// Default is "https://spreadsheets.google.com".
	BaseURL string

	Client *http.Client

	// Maximum number of concurrent connections.
	// Default is 300.
	MaxConns int

	// Maximum number of cells to synchronize at once.
	// Default is 1000.
	MaxSync int

	// private or public.  Default is private.
	Visibility VisibilityState

	// Return all empty cells.
	ReturnEmpty bool
}

Service represents a Sheets API service instance. Service is the main entry point into using this package.

func (*Service) Get

func (s *Service) Get(ID string) (*Spreadsheet, error)

Get returns a spreadsheet with the given ID.

type Spreadsheet

type Spreadsheet struct {
	XMLName    xml.Name     `xml:"feed"`
	Title      string       `xml:"title"`
	Links      []link       `xml:"link"`
	Worksheets []*Worksheet `xml:"entry"`
	// contains filtered or unexported fields
}

Spreadsheet represents a spreadsheet. Spreadsheets contain worksheets.

func (*Spreadsheet) ExistsTitled

func (ss *Spreadsheet) ExistsTitled(title string) bool

ExistsTitled returns whether there is a sheet titlted given parameter

func (*Spreadsheet) FindByID

func (ss *Spreadsheet) FindByID(id string) (*Worksheet, error)

FindByID returns the worksheet of passed id.

func (*Spreadsheet) FindByTitle

func (ss *Spreadsheet) FindByTitle(title string) (*Worksheet, error)

FindByTitle returns the worksheet of passed title.

func (*Spreadsheet) Get

func (ss *Spreadsheet) Get(i int) (*Worksheet, error)

Get returns the worksheet at a given index.

func (*Spreadsheet) NewWorksheet

func (ss *Spreadsheet) NewWorksheet(title string, rowCount, colCount int) (*Worksheet, error)

NewWorksheet adds a new worksheet.

type VisibilityState

type VisibilityState int

VisibilityState represents a visibility state for a spreadsheet.

const (
	// PrivateVisibility represents a private visibility state for a spreadsheet.  Private
	// spreadsheets require authentication.
	PrivateVisibility VisibilityState = iota

	// PublicVisibility represents a public visibility state for a spreadsheet.  Public
	// spreadsheets can be viewed without authentication.
	PublicVisibility
)

func (VisibilityState) String

func (v VisibilityState) String() string

type Worksheet

type Worksheet struct {
	ID      string    `xml:"id"`
	Updated time.Time `xml:"updated"`
	Title   string    `xml:"title"`
	Content string    `xml:"content"`
	Links   []link    `xml:"link"`

	CellsFeed string
	EditLink  string
	CSVLink   string
	MaxRowNum int
	MaxColNum int
	Rows      [][]*Cell
	// contains filtered or unexported fields
}

A Worksheet represents a worksheet inside a spreadsheet.

func (*Worksheet) Destroy

func (ws *Worksheet) Destroy() error

Destroy deletes a worksheet.

func (*Worksheet) DocsURL

func (ws *Worksheet) DocsURL() string

DocsURL is a URL to the google docs spreadsheet (human readable)

func (*Worksheet) Synchronize

func (ws *Worksheet) Synchronize() error

Synchronize saves the modified cells.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL