xls2csv

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package xls2csv is a Golang package which converts XLS file to CSV records. It's based on libxls and xls2csv.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func XLS2CSV

func XLS2CSV(xlsFile string, sheetID int) (records [][]string, err error)

XLS2CSV converts XLS file to CSV records.

Params:
  xlsFile: XLS file name.
  sheetID: sheet ID to be converted. It's 0-based.
Return:
  records: CSV records. Each record is a slice of fields.
           See https://godoc.org/encoding/csv#Reader.ReadAll for more info.
Example

Run "go test -c && ./xls2csv.test" to test.

package main

import (
	"fmt"
	"log"

	"github.com/goshlanguage/xls2csv-go/xls2csv"
	"github.com/northbright/pathhelper"
)

func main() {
	const xlsFile string = "./files/my.xls"
	var err error
	records := [][]string{}

	// Get absolute path of XLS file.
	f, _ := pathhelper.GetAbsPath(xlsFile)

	// Call XLS2CSV() to convert XLS and get all records.
	if records, err = xls2csv.XLS2CSV(f, 0); err != nil {
		log.Printf("XLS2CSV() error: %v\n", err)
		goto end
	}

	for i, row := range records {
		fmt.Printf("%v", row)
		if i != len(records)-1 {
			fmt.Printf("\n")
		}
	}

end:
}
Output:

[Product Vendor Price]
[iPhone 7 Plus Gold 128GB Apple 7188]
[iPhone 7 Plus Gold 128GB JD 6399]
[iPhone 7 Plus Gold 128GB YHD 6488]
[iPhone 7 Gold 128GB Apple 6188]
[iPhone 7 Gold 128GB JD 5499]
[iPhone 7 Gold 128GB YHD 5498]

Types

This section is empty.

Jump to

Keyboard shortcuts

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