summaryrefslogtreecommitdiff
path: root/copy.go
diff options
context:
space:
mode:
Diffstat (limited to 'copy.go')
-rw-r--r--copy.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/copy.go b/copy.go
new file mode 100644
index 0000000..a91d30e
--- /dev/null
+++ b/copy.go
@@ -0,0 +1,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
+}