tubular

package module
v0.0.0-...-b26bacb Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2017 License: BSD-2-Clause Imports: 7 Imported by: 0

README

tubular

tubular is a small abstraction library for writing XLSX files and separated values files using the same data structure. For the XLSX internally it uses github.com/tealeg/xlsx.

Installation

Install the library using go get

$ go get github.com/stuartaroth/tubular
Usage

GoDoc

tubular requires clients to create a slice of Page:

Page

type Page struct {
  Name string
  Rows [][]interface{}
}

For an example of use, see below and the examples directory:

Example Usage

You can find this code at https://github.com/stuartaroth/tubular/blob/master/examples/xlsx.go

package main

import (
  "fmt"
  "github.com/stuartaroth/tubular"
)

func main() {
  pages := []tubular.Page{
    tubular.Page{
      Name: "Horror",
      Rows: [][]interface{}{
        []interface{}{"Title", "Director", "Year Released"},
        []interface{}{"A Nightmare on Elm Street", "Wes Craven", 1984},
        []interface{}{"Black Christmas", "Bob Clark", 1974},
        []interface{}{"Friday the 13th", "Sean S. Cunningham", 1980},
        []interface{}{"Halloween", "John Carpenter", 1978},
        []interface{}{"The Texas Chain Saw Massacre", "Tobe Hooper", 1974},
      },
    },
    tubular.Page{
      Name: "Sci-Fi",
      Rows: [][]interface{}{
        []interface{}{"Title", "Director", "Year Released"},
        []interface{}{"2001: A Spacey Odyssey", "Stanley Kubrick", 1968},
        []interface{}{"Aliens", "James Cameron", 1986},
        []interface{}{"Back to the Future", "Robert Zemeckis", 1985},
        []interface{}{"Blade Runner", "Ridley Scott", 1982},
        []interface{}{"Star Wars", "George Lucas", 1977},
      },
    },
  }

  filename, err := tubular.WriteXLSXFile("Movies", pages)
  if err != nil {
    fmt.Println("Error writing xlsx file:", err)
    return
  }

  fmt.Println("Successfully wrote xlsx file:", filename)
}
License

BSD-2 clause - see LICENSE for more details

Documentation

Overview

Package tubular is an abstraction library for writing XLSX files and separated values files

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteSeparatedValuesFile

func WriteSeparatedValuesFile(filenameWithoutEnding string, fileEnding string, newLineString string, separatorString string, pages []Page) (string, error)

WriteSeparatedValuesFile allows you to write multiple separated values files

filenameWithouEnding is the desired filename of the created zipfile.

pages is a slice of Page. Each Page will create a separate file

WriteSeparatedValuesFile will create an zip file that will include a file per passed page and return the created filename and an error

func WriteXLSXFile

func WriteXLSXFile(filenameWithoutEnding string, pages []Page) (string, error)

WriteXLSXFile allows you to write an XLSX file

filenameWithouEnding is the desired filename.

pages is a slice of Page. Each Page will create a sheet in the XLSX file

WriteXLSXFile will create an XLSX file and return the created filename and an error

Types

type Page

type Page struct {
	Name string
	Rows [][]interface{}
}

Page is the struct used to build either a separated values file or an xlsx sheet

Name is the filename or sheet name depending on what you build

Rows are the tabular data that will be written in the file or sheet

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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