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 }