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

github.com/acidlemon/go-xlsx-parser

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/acidlemon/go-xlsx-parser

v0.1.0
Source
Go
Version published
Created
Source

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 30 Sep 2019

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