🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

github.com/dsp163/go-xlsx-parser

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/dsp163/go-xlsx-parser

v0.1.1
Version published
Created

go-xlsx-parser

SAX like streaming xlsx parser

SYNOPSIS

doc := xlsx.Open("your.xlsx")
parser := &MyParser{}
doc.ParseSheet("Sheet 1", parser)
type MyParser struct{}
func (p *MyParser) ReadRow(rowCount int, columns []interface{}) {
     // write your parser here!
}

Example

package main

import (
	"fmt"
	"strings"
	"time"

	"github.com/acidlemon/go-xlsx-parser/xlsx"
)

func main() {
	doc := xlsx.Open("xlsx/test.xlsx")
	parser := &MyParser{}

	doc.ParseSheet("シート1", parser)
}

type MyParser struct{}

// see xlsx/parser.go
func (p *MyParser) ReadRow(rowCount int, columns []interface{}) {
	fmt.Printf("Line %d:\n", rowCount)
	data := []string{}
	for _, value := range columns {
		switch v := value.(type) {
		case string:
			data = append(data, `"`+v+`"`)

		case int64:
			data = append(data, fmt.Sprintf("%d", v))

		case float64:
			data = append(data, fmt.Sprintf("%f", v))

		case time.Time:
			data = append(data, v.Format(`"2006-01-02 15:04:05"`))
		}
	}

	fmt.Println(" ", strings.Join(data, `,`))
}

Enjoy!

FAQs

Package last updated on 15 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts