Skip to content

Instantly share code, notes, and snippets.

@nicerobot
Last active August 7, 2016 16:42
Show Gist options
  • Select an option

  • Save nicerobot/779fb8000a0184ab8314ac9e6aa860eb to your computer and use it in GitHub Desktop.

Select an option

Save nicerobot/779fb8000a0184ab8314ac9e6aa860eb to your computer and use it in GitHub Desktop.
ACS SeqNN.xls golang

Test case for extrame/xls/issues/12

git clone https://gist.github.com/779fb8000a0184ab8314ac9e6aa860eb.git
cd 779fb8000a0184ab8314ac9e6aa860eb
make
.PHONY : build run
run: seq
./seq Seq99.xls 2>&1 | grep -B3 B24126_036
build: seq
seq: seq.go
go build -o $@
package main
import (
"flag"
"fmt"
"log"
"os"
"path/filepath"
"github.com/extrame/xls"
)
//
func main() {
flag.Parse()
path := flag.Arg(0)
if fi, err := os.Stat(path); err != nil {
log.Fatalln(err)
} else if fi.IsDir() {
path = filepath.Join(path, "Seq*.xls")
}
if files, err := filepath.Glob(path); err != nil {
log.Fatalln(err)
} else {
readAll(files)
}
}
//
func readAll(files []string) {
for _, file := range files {
parse(file)
}
}
//
func parse(file string) {
if w, err := xls.Open(file, "r"); err != nil {
log.Fatal(err)
} else {
cells := w.ReadAllCells(10000)
if len(cells) != 4 {
log.Fatalln("Expecting four rows, two for estimates, two for margins of error: " + file)
}
{
header := cells[0]
values := cells[1]
fmt.Printf("\n# %s\n", file)
for i, v := range values {
if i >= 6 {
fmt.Printf("%s\t%s\n", header[i], v)
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment