sheety

package module
v0.0.0-...-72b8c36 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2019 License: MIT Imports: 10 Imported by: 0

README

Sheety

Easily load csv or xlsx formats into a slice of structs

Installation

go get -u github.com/chriswalz/Sheety

Usage

    package main

    import (
    	"github.com/chriswalz/sheety"
    )

    type Student struct {
    	ID    float64
    	Grade float64
    }

    func main()  {
        s, err := sheety.OpenCSV("grades.csv")
    	if err != nil {
    		panic(err)
    	}
     
        // use pointer to struct
    	students := make([]*Student, 0, 3)
    
    	// map column index to struct field name
    	// First index starts at 1 NOT 0
    	err = s.ReadRows(1, &students, map[int]string{
    		1: "ID",
    		2: "Grade",
    	})
    	for _, v := range students {
    		// do work 
    	}
   }

See sheety_test.go for example usage

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SpreadCSV

type SpreadCSV struct {
	// contains filtered or unexported fields
}

func OpenCSV

func OpenCSV(excelFileName string) (*SpreadCSV, error)

func (*SpreadCSV) ReadRows

func (s *SpreadCSV) ReadRows(startIndex int, bb interface{}, m map[int]string) error

ReadRows takes a starting row index, a pointer to slice, and a mapping from spreadsheet to struct

type Spreadsheet

type Spreadsheet struct {
	// contains filtered or unexported fields
}

func OpenSpreadsheet

func OpenSpreadsheet(excelFileName string) (*Spreadsheet, error)

func (*Spreadsheet) ReadRows

func (s *Spreadsheet) ReadRows(start int, bb interface{}, m map[int]string)

ReadRows takes a starting row index, a pointer to slice, and a mapping from spreadsheet to struct

func (*Spreadsheet) SaveRows

func (s *Spreadsheet) SaveRows(start int, bb interface{}, m map[int]string, path string)

ReadRows takes a starting row index, a pointer to slice, and a mapping from spreadsheet to struct

Jump to

Keyboard shortcuts

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