Exemplo n.º 1
0
func main() {

	var seq <-chan string

	if *filename != "" {

		// file mode
		c, err := reader.OpenXLSXSheet(*filename, 0)
		if err != nil {
			panic(err)
			return
		}

		if *max == 0 {
			*max = c.Len() // last row
		}

		fmter := func(n int) (str string, err error) {
			strs, err := reader.ReadMulti(c, 0, 1)(n)
			if err != nil {
				return
			}
			str = strings.Join(strs, ", ")
			return
		}
		seq = formatNum(fmter, uniqueInt(randInts(*min-1, *max-1)))
	} else {
		// raw number mode
		l := len(fmt.Sprintf("%d", *max))
		seq = formatNum(padNumToStr(l), uniqueInt(randInts(*min, *max)))
	}

	url := "https://github.com/yookoala/lottery"
	fmt.Printf("\nSource code: %s\n\n", url)
	fmt.Printf("Max: %d\n", *max)
	fmt.Printf("Min: %d\n", *min)
	fmt.Printf("=================\n\n")

	reader := bufio.NewReader(os.Stdin)
	for n := range seq {
		t := time.Now().Format("15:04:05.999")
		t += strings.Repeat("0", 12-len(t))
		fmt.Printf("[%s] %s", t, n)
		reader.ReadString('\n')
	}
}
Exemplo n.º 2
0
func TestXLSXReadMulti(t *testing.T) {

	f, err := reader.OpenXLSXSheet("./_test/test.xlsx", 0)
	if err != nil {
		t.Errorf("unable to open xlsx file: %#v", err.Error())
	}

	for i := 0; i < f.Len(); i++ {
		strs, err := reader.ReadMulti(f, 0, 1)(i)
		if err != nil {
			t.Errorf("unable to ReadMulti on line %d: %#v",
				i, err.Error())
		}

		res := strings.Join(strs, ", ")
		exp := testXLSXdata[i][0] + ", " + testXLSXdata[i][1]
		if res != exp {
			t.Errorf("row %d exptects %#v, got %#v",
				exp, res)
		}

		t.Logf("%#v", res)
	}
}