FileToSlice.go 757 B

12345678910111213141516171819202122232425262728293031323334
  1. package xlsx
  2. // get all raw data from excel
  3. // output index mean=> sheetIndex ,row ,cell ,value
  4. // not remove any cells
  5. func FileToSlice(path string) ([][][]string, error) {
  6. f, err := OpenFile(path)
  7. if err != nil {
  8. return nil, err
  9. }
  10. return f.ToSlice()
  11. }
  12. // get all raw data from excel
  13. // output index mean=> sheetIndex ,row ,cell ,value
  14. // not remove any cells
  15. func (file *File) ToSlice() (output [][][]string, err error) {
  16. output = [][][]string{}
  17. for _, sheet := range file.Sheets {
  18. s := [][]string{}
  19. for _, row := range sheet.Rows {
  20. if row == nil {
  21. continue
  22. }
  23. r := []string{}
  24. for _, cell := range row.Cells {
  25. r = append(r, cell.String())
  26. }
  27. s = append(s, r)
  28. }
  29. output = append(output, s)
  30. }
  31. return output, nil
  32. }