excelize_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package excelize
  2. import (
  3. "strconv"
  4. "testing"
  5. )
  6. func TestExcelize(t *testing.T) {
  7. // Test update a XLSX file
  8. file := OpenFile("./test/Workbook1.xlsx")
  9. file.SetCellInt("SHEET2", "B2", 100)
  10. file.SetCellStr("SHEET2", "C11", "Knowns")
  11. file.NewSheet(3, "TestSheet")
  12. file.SetCellInt("Sheet3", "A23", 10)
  13. file.SetCellStr("SHEET3", "b230", "10")
  14. file.SetCellStr("SHEET10", "b230", "10")
  15. file.SetActiveSheet(2)
  16. for i := 1; i <= 300; i++ {
  17. file.SetCellStr("SHEET3", "c"+strconv.Itoa(i), strconv.Itoa(i))
  18. }
  19. err := file.Save()
  20. if err != nil {
  21. t.Log(err)
  22. }
  23. // Test write file to given path
  24. err = file.WriteTo("./test/Workbook_2.xlsx")
  25. if err != nil {
  26. t.Log(err)
  27. }
  28. // Test write file to not exist directory
  29. err = file.WriteTo("")
  30. if err != nil {
  31. t.Log(err)
  32. }
  33. // Test create a XLSX file
  34. file2 := CreateFile()
  35. file2.NewSheet(2, "XLSXSheet2")
  36. file2.NewSheet(3, "XLSXSheet3")
  37. file2.SetCellInt("Sheet2", "A23", 56)
  38. file2.SetCellStr("SHEET1", "B20", "42")
  39. file2.SetActiveSheet(0)
  40. err = file2.WriteTo("./test/Workbook_3.xlsx")
  41. if err != nil {
  42. t.Log(err)
  43. }
  44. // Test read cell value with given illegal rows number
  45. file.GetCellValue("Sheet2", "a-1")
  46. // Test read cell value with given lowercase column number
  47. file.GetCellValue("Sheet2", "a5")
  48. file.GetCellValue("Sheet2", "C11")
  49. file.GetCellValue("Sheet2", "D11")
  50. file.GetCellValue("Sheet2", "D12")
  51. // Test read cell value with given axis large than exists row
  52. file.GetCellValue("Sheet2", "E13")
  53. }