excelize_test.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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.Error(err)
  11. }
  12. file = SetCellInt(file, "SHEET2", "B2", 100)
  13. file = SetCellStr(file, "SHEET2", "C11", "Knowns")
  14. file = NewSheet(file, 3, "TestSheet")
  15. file = SetCellInt(file, "Sheet3", "A23", 10)
  16. file = SetCellStr(file, "SHEET3", "b230", "10")
  17. file = SetActiveSheet(file, 2)
  18. if err != nil {
  19. t.Error(err)
  20. }
  21. for i := 1; i <= 300; i++ {
  22. file = SetCellStr(file, "SHEET3", "c"+strconv.Itoa(i), strconv.Itoa(i))
  23. }
  24. err = Save(file, "./test/Workbook_2.xlsx")
  25. // Test create a XLSX file
  26. file2 := CreateFile()
  27. file2 = NewSheet(file2, 2, "TestSheet2")
  28. file2 = NewSheet(file2, 3, "TestSheet3")
  29. file2 = SetCellInt(file2, "Sheet2", "A23", 10)
  30. file2 = SetCellStr(file2, "SHEET1", "B20", "10")
  31. err = Save(file2, "./test/Workbook_3.xlsx")
  32. if err != nil {
  33. t.Error(err)
  34. }
  35. // Test read cell value
  36. file, err = OpenFile("./test/Workbook1.xlsx")
  37. if err != nil {
  38. t.Error(err)
  39. }
  40. GetCellValue(file, "Sheet2", "a5")
  41. GetCellValue(file, "Sheet2", "D11")
  42. GetCellValue(file, "Sheet2", "D12")
  43. GetCellValue(file, "Sheet2", "E12")
  44. }