excelize_test.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 read cell value with given axis large than exists row
  28. file.GetCellValue("Sheet2", "E13")
  29. for i := 1; i <= 300; i++ {
  30. file.SetCellStr("SHEET3", "c"+strconv.Itoa(i), strconv.Itoa(i))
  31. }
  32. err = file.Save()
  33. if err != nil {
  34. t.Log(err)
  35. }
  36. // Test write file to given path
  37. err = file.WriteTo("./test/Workbook_2.xlsx")
  38. if err != nil {
  39. t.Log(err)
  40. }
  41. // Test write file to not exist directory
  42. err = file.WriteTo("")
  43. if err != nil {
  44. t.Log(err)
  45. }
  46. // Test create a XLSX file
  47. file2 := CreateFile()
  48. file2.NewSheet(2, "XLSXSheet2")
  49. file2.NewSheet(3, "XLSXSheet3")
  50. file2.SetCellInt("Sheet2", "A23", 56)
  51. file2.SetCellStr("SHEET1", "B20", "42")
  52. file2.SetActiveSheet(0)
  53. err = file2.WriteTo("./test/Workbook_3.xlsx")
  54. if err != nil {
  55. t.Log(err)
  56. }
  57. // Test open a XLSX file with given illegal path
  58. _, err = OpenFile("./test/Workbook.xlsx")
  59. if err != nil {
  60. t.Log(err)
  61. }
  62. }