goxlsxwriter

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2018 License: BSD-2-Clause-Views Imports: 3 Imported by: 10

README

goxlsxwriter

Build Status Go Report Card Coverage Status

goxlsxwriter provides Go bindings for the libxlsxwriter C library.

Install

goxlsxwriter requires the libxslxwriter library to be installed. To build from source via Git:

$ git clone https://github.com/jmcnamara/libxlsxwriter.git
$ cd libxlsxwriter
$ make
$ make install

Visit http://libxlsxwriter.github.io/getting_started.html for more information on installing libxlsxwriter.

Sample Use

package main

import (
    "github.com/fterrag/goxlsxwriter"
)

func main() {
    workbook := goxlsxwriter.NewWorkbook("example.xlsx", nil)
    worksheet := goxlsxwriter.NewWorksheet(workbook, "Sheet 1")

    format := goxlsxwriter.NewFormat(workbook)

    format.SetFontName("Verdana")
    format.SetFontSize(8)
    format.SetFontColor(0x008000)

    worksheet.WriteString(0, 0, "Hello from A1!", format)
    worksheet.WriteString(4, 1, "This cell is B5", nil)

    options := &goxlsxwriter.ImageOptions{
        XScale: 0.5,
        YScale: 0.5,
    }
    worksheet.InsertImage(1, 3, "resources/gopher.png", options)

    workbook.Close()
}

Todo

  • Increase test coverage
  • Documentation
  • Expand libxlsxwriter API coverage

Contributing

  • Submit a PR (tests and documentation included)
  • Add or improve documentation
  • Report issues
  • Suggest new features or enhancements

Documentation

Index

Constants

View Source
const (
	// Single underline.
	UNDERLINE_SINGLE int = C.LXW_UNDERLINE_SINGLE

	// Double underline.
	UNDERLINE_DOUBLE int = C.LXW_UNDERLINE_DOUBLE

	// Single accounting underline.
	UNDERLINE_SINGLE_ACCOUNTING int = C.LXW_UNDERLINE_SINGLE_ACCOUNTING

	// Double accounting line.
	UNDERLINE_DOUBLE_ACCOUNTING int = C.LXW_UNDERLINE_DOUBLE_ACCOUNTING
)

UNDERLINE_* constants are to be used with SetUnderline().

View Source
const (
	// Solid.
	PATTERN_SOLID int = C.LXW_PATTERN_SOLID

	// Medium gray.
	PATTERN_MEDIUM_GRAY int = C.LXW_PATTERN_MEDIUM_GRAY

	// Dark gray.
	PATTERN_DARK_GRAY int = C.LXW_PATTERN_DARK_GRAY

	// Light gray.
	PATTERN_LIGHT_GRAY int = C.LXW_PATTERN_LIGHT_GRAY

	// Dark horizontal line.
	PATTERN_DARK_HORIZONTAL int = C.LXW_PATTERN_DARK_HORIZONTAL

	// Dark vertical line.
	PATTERN_DARK_VERTICAL int = C.LXW_PATTERN_DARK_VERTICAL

	// Dark diagonal stripe.
	PATTERN_DARK_DOWN int = C.LXW_PATTERN_DARK_DOWN

	// Reverse dark diagonal stripe.
	PATTERN_DARK_UP int = C.LXW_PATTERN_DARK_UP

	// Dark grid.
	PATTERN_DARK_GRID int = C.LXW_PATTERN_DARK_GRID

	// Dark trellis.
	PATTERN_DARK_TRELLIS int = C.LXW_PATTERN_DARK_TRELLIS

	// Light horizontal line.
	PATTERN_LIGHT_HORIZONTAL int = C.LXW_PATTERN_LIGHT_HORIZONTAL

	// Light vertical line.
	PATTERN_LIGHT_VERTICAL int = C.LXW_PATTERN_LIGHT_VERTICAL

	// Light diagonal stripe.
	PATTERN_LIGHT_DOWN int = C.LXW_PATTERN_LIGHT_DOWN

	// Reverse light diagonal stripe.
	PATTERN_LIGHT_UP int = C.LXW_PATTERN_LIGHT_UP

	// Light grid.
	PATTERN_LIGHT_GRID int = C.LXW_PATTERN_LIGHT_GRID

	// Light trellis.
	PATTERN_LIGHT_TRELLIS int = C.LXW_PATTERN_LIGHT_TRELLIS

	// 12.5% gray.
	PATTERN_GRAY_125 int = C.LXW_PATTERN_GRAY_125

	// 6.25% gray.
	PATTERN_GRAY_0625 int = C.LXW_PATTERN_GRAY_0625
)

PATTERN_* constants are to be used with SetPattern().

Variables

This section is empty.

Functions

This section is empty.

Types

type Format

type Format struct {
	CFormat *C.struct_lxw_format
}

Format represents an Excel style used to apply formatting to cells.

func NewFormat

func NewFormat(workbook *Workbook) *Format

NewFormat creates and returns a new instance of Format.

func (*Format) SetBackgroundColor

func (f *Format) SetBackgroundColor(color int)

SetBackgroundColor sets the background color.

func (*Format) SetBold

func (f *Format) SetBold()

SetBold sets the font to be bold.

func (*Format) SetFontColor

func (f *Format) SetFontColor(color int)

SetFontColor sets the font color.

func (*Format) SetFontName

func (f *Format) SetFontName(fontName string)

SetFontName sets the format's font face.

func (*Format) SetFontSize

func (f *Format) SetFontSize(size int)

SetFontSize sets the font size.

func (*Format) SetItalic

func (f *Format) SetItalic()

SetItalic sets the font to be italic.

func (*Format) SetNumericalFormat

func (f *Format) SetNumericalFormat(numberFormat string)

SetNumericalFormat sets the numerical format. It controls whether a number is displayed as an integer, a floating point number, a date, a currency value or some other user defined format (e.g., "d mmm yyyy").

func (*Format) SetPattern

func (f *Format) SetPattern(pattern int)

SetPattern sets the pattern to the specific PATTERN_* pattern.

func (*Format) SetUnderline

func (f *Format) SetUnderline(style int)

SetUnderline sets the font to be underline using the specified UNDERLINE_* style.

type ImageOptions

type ImageOptions struct {
	XOffset int
	YOffset int
	XScale  float64
	YScale  float64
}

ImageOptions contains options to be set when inserting an image into a worksheet.

type Workbook

type Workbook struct {
	CWorkbook *C.struct_lxw_workbook
}

Workbook represents an Excel workbook.

func NewWorkbook

func NewWorkbook(filename string, options *WorkbookOptions) *Workbook

NewWorkbook create and returns a new instance of Workbook.

func (*Workbook) Close

func (w *Workbook) Close() error

Close closes the workbook and writes the XLSX file to disk.

type WorkbookOptions

type WorkbookOptions struct {
	ConstantMemory int
	TmpDir         string
}

WorkbookOptions contains options to be set when creating a new Workbook.

type Worksheet

type Worksheet struct {
	CWorksheet *C.struct_lxw_worksheet
	Workbook   *Workbook
}

Worksheet represents an Excel worksheet.

func NewWorksheet

func NewWorksheet(workbook *Workbook, sheetName string) *Worksheet

NewWorksheet creates and returns a new instance of Worksheet.

func (*Worksheet) InsertImage

func (w *Worksheet) InsertImage(row int, col int, filename string, options *ImageOptions) error

InsertImage inserts an image at the specified row and column and applies options.

func (*Worksheet) WriteBlank

func (w *Worksheet) WriteBlank(row int, col int, format *Format) error

WriteBlank writes a "blank" cell at the specified row and column and applies an optional format. Excel differentiates between an empty cell and a blank cell. An empty cell is a cell which doesn't contain data or formatting. A blank cell doesn't contain data but does contain formatting.

func (*Worksheet) WriteBool

func (w *Worksheet) WriteBool(row int, col int, value bool, format *Format) error

WriteBool writes a boolean value at the specified row and column and applies an optional format.

func (*Worksheet) WriteFloat

func (w *Worksheet) WriteFloat(row int, col int, value float64, format *Format) error

WriteFloat writes a float64 value at the specified row and column and applies an optional format.

func (*Worksheet) WriteFormula

func (w *Worksheet) WriteFormula(row int, col int, formula string, format *Format) error

WriteFormula writes a formula value at the specified row and column and applies an optional format.

func (*Worksheet) WriteInt

func (w *Worksheet) WriteInt(row int, col int, value int, format *Format) error

WriteInt writes an integer value at the specified row and column and applies an optional format.

func (*Worksheet) WriteString

func (w *Worksheet) WriteString(row int, col int, value string, format *Format) error

WriteString writes a string value at the specified row and column and applies an optional format.

func (*Worksheet) WriteUrl

func (w *Worksheet) WriteUrl(row int, col int, url string, display string, format *Format) error

WriteUrl writes a URL and a display string at the specified row and column and applies an optional format to the display string. If the specified display string is empty, the URL will be used.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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