excelize_test.go 1.8 KB

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