xlsx

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2022 License: MIT Imports: 10 Imported by: 0

README

xlsx

Go Report Card Build Status codecov

Working with XLSX is most of the times a pain (is built with XML). This package aims to work with XLSX files to extract only the data inside. It doesn't manage styles or any other fancy feature. It supports shared strings (because it's not a fancy feature) and it is fast and easy to use.

package main

import (
	"fmt"
	"log"
	"os"

	"github.com/xenking/fast-xlsx"
)

func main() {
	// open the XLSX file.
	ws, err := xlsx.Open(os.Args[1])
	if err != nil {
		log.Fatalln(err)
	}
	defer ws.Close() // do not forget to close

	// iterate over the sheets
	for _, wb := range ws.Sheets() {
		fmt.Println(wb.Name)
		
		r, err := wb.Open()
		if err != nil {
			log.Fatalln(err)
		}

		for r.Next() { // get next row
			fmt.Println(r.Row())
		}
		if r.Error() != nil { // error checking
			log.Fatalln(r.Error())
		}
		// don't forget to close the sheet!!
		r.Close()
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustStringToInt

func MustStringToInt(s string) int64

MustStringToInt returns a int64 ignoring any error.

func MustStringToUint

func MustStringToUint(s string) uint64

MustStringToUint returns a uint64 ignoring any error.

func StringToDate

func StringToDate(s string) (t time.Time, err error)

StringToDate converts the string from string to float and to time.Time

func StringToInt

func StringToInt(s string) (int64, error)

StringToInt converts the string to an int64.

func StringToUint

func StringToUint(s string) (uint64, error)

StringToUint converts the string to an uint64.

func ToDate

func ToDate(n float64) time.Time

ToDate converts the date from excel format to time.Time

Types

type Sheet

type Sheet struct {
	Name string
	// contains filtered or unexported fields
}

Sheet represents an spreadsheet.

func (*Sheet) Open

func (s *Sheet) Open() (*SheetReader, error)

Open opens a sheet to read it.

type SheetReader

type SheetReader struct {
	// ReuseRecord ...
	ReuseRecord bool
	// contains filtered or unexported fields
}

SheetReader creates an structure able to read row by row the spreadsheet data.

func (*SheetReader) Close

func (sr *SheetReader) Close() error

Close closes the sheet file reader.

func (*SheetReader) Error

func (sr *SheetReader) Error() error

Error returns the error occurred during Next().

If no error is returned here but Next() returned false it can be caused because the EOF was reach.

func (*SheetReader) Next

func (sr *SheetReader) Next() bool

Next returns true if the row has been successfully readed.

if false is returned check the Error() function.

func (*SheetReader) Read

func (sr *SheetReader) Read() (record []string, err error)

Read returns the row or error

func (*SheetReader) Row

func (sr *SheetReader) Row() []string

Row returns the last readed row.

type XLSX

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

XLSX ...

func Open

func Open(filename string) (*XLSX, error)

Open just opens the file for reading.

func OpenReader

func OpenReader(r io.ReaderAt, size int64) (*XLSX, error)

OpenReader opens the reader as XLSX file.

func (*XLSX) Close

func (xlsx *XLSX) Close() error

Close closes all the buffers and readers.

func (*XLSX) SharedStrings

func (xlsx *XLSX) SharedStrings() []string

SharedStrings returns the shared strings.

func (*XLSX) Sheets

func (xlsx *XLSX) Sheets() []*Sheet

Sheets returns the sheets.

Directories

Path Synopsis
+build ignore
+build ignore

Jump to

Keyboard shortcuts

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