Skip to content

n-sys/xlsReader

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

xlsReader

Golang library that (barely) reads old .xls files.

Forked from github.com/shakinm/xlsReader.

Modified to ignore date and datetime formats since this code was being messed up by locale specs.

Installation

$ go get github.com/n-sys/xlsReader

Using

package main

import (
	"fmt"
	"github.com/n-sys/xlsReader/xls"
	"log"
)

func main() {

	workbook, err := xls.OpenFile("small_1_sheet.xls")

	if err!=nil {
		log.Panic(err.Error())
	}

	// Number of sheets in the workbook
	//
	// for i := 0; i <= workbook.GetNumberSheets()-1; i++ {}

	fmt.Println(workbook.GetNumberSheets())

	sheet, err := workbook.GetSheet(0)

	if err!=nil {
		log.Panic(err.Error())
	}

	// Print sheet name
	println(sheet.GetName())

	// Print the number of rows in the sheet
	println(sheet.GetNumberRows())

	for i := 0; i <= sheet.GetNumberRows(); i++ {
		if row, err := sheet.GetRow(i); err == nil {
			if cell, err := row.GetCol(1); err == nil {

				// Cell value, string type
				fmt.Println(cell.GetString())

				//fmt.Println(cell.GetInt64())
				//fmt.Println(cell.GetFloat64())

				// Cell type (records)
				fmt.Println(cell.GetType())

				// Receiving a formatted string, for example, for cells with a date or a percentage
				xfIndex:=cell.GetXFIndex()
				formatIndex:=workbook.GetXFbyIndex(xfIndex)
				format:=workbook.GetFormatByIndex(formatIndex.GetFormatIndex())
				fmt.Println(format.GetFormatString(cell))

			}
		}
	}
}

About

Package for reading XLS files but using a single forced format for all dates and datetimes.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%