1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
package badtudexo
import (
xl "anyxcelize"
"fmt"
st "saggytrousers"
"errors"
)
func Copy(file *xl.File, sheet, target string, failOnEmpty bool) (error, bool) {
/* Grab all rows from the sheet. */
st.Log(true, "Grabbing rows...")
rows, err := file.GetRowsGeneric(sheet)
if err != nil {
return errors.New(fmt.Sprintf("bt.Copy: failed to get rows with error %v", err)), false
}
st.Log(true, " done!\n")
if len(rows) == 0 {
return errors.New(fmt.Sprintf("bt.Copy: rows empty")), true
}
/* Copy into new file. */
saved := xl.NewFile()
saved.SetSheetName("Sheet1", sheet)
count := 1
st.Log(false, fmt.Sprintf("len(rows) = %v\n", len(rows)))
for _, row := range rows {
loc := fmt.Sprintf("A%v", count)
st.Log(false, fmt.Sprintf("%v:%v: %v\n", sheet, loc, row))
saved.SetSheetRow(sheet, loc, &row)
count++
}
/* Save file. */
return saved.SaveAs(target), false
}
|