2016-08-30 11:51:31 +08:00
|
|
|
package excelize
|
|
|
|
|
|
|
|
import (
|
2016-08-30 14:00:21 +08:00
|
|
|
"strconv"
|
2016-08-30 11:51:31 +08:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestExcelize(t *testing.T) {
|
|
|
|
// Test update a XLSX file
|
2016-09-06 21:20:24 +08:00
|
|
|
file, err := OpenFile("./test/Workbook1.xlsx")
|
|
|
|
if err != nil {
|
|
|
|
t.Log(err)
|
|
|
|
}
|
|
|
|
file.UpdateLinkedValue()
|
2016-09-07 20:09:02 +08:00
|
|
|
file.SetCellInt("SHEET2", "A1", 100)
|
2016-09-05 16:37:15 +08:00
|
|
|
file.SetCellStr("SHEET2", "C11", "Knowns")
|
|
|
|
file.NewSheet(3, "TestSheet")
|
|
|
|
file.SetCellInt("Sheet3", "A23", 10)
|
|
|
|
file.SetCellStr("SHEET3", "b230", "10")
|
|
|
|
file.SetCellStr("SHEET10", "b230", "10")
|
|
|
|
file.SetActiveSheet(2)
|
2016-09-06 21:20:24 +08:00
|
|
|
// Test read cell value with given illegal rows number
|
|
|
|
file.GetCellValue("Sheet2", "a-1")
|
|
|
|
// Test read cell value with given lowercase column number
|
|
|
|
file.GetCellValue("Sheet2", "a5")
|
|
|
|
file.GetCellValue("Sheet2", "C11")
|
|
|
|
file.GetCellValue("Sheet2", "D11")
|
|
|
|
file.GetCellValue("Sheet2", "D12")
|
2016-09-09 19:39:41 +08:00
|
|
|
// Test SetCellValue function
|
|
|
|
file.SetCellValue("Sheet2", "F1", "Hello")
|
|
|
|
file.SetCellValue("Sheet2", "G1", []byte("World"))
|
|
|
|
file.SetCellValue("Sheet2", "F2", 42)
|
|
|
|
file.SetCellValue("Sheet2", "G2", nil)
|
2016-09-06 21:20:24 +08:00
|
|
|
// Test read cell value with given axis large than exists row
|
|
|
|
file.GetCellValue("Sheet2", "E13")
|
|
|
|
|
2016-09-05 16:37:15 +08:00
|
|
|
for i := 1; i <= 300; i++ {
|
|
|
|
file.SetCellStr("SHEET3", "c"+strconv.Itoa(i), strconv.Itoa(i))
|
2016-08-30 11:51:31 +08:00
|
|
|
}
|
2016-09-06 21:20:24 +08:00
|
|
|
err = file.Save()
|
2016-08-30 11:51:31 +08:00
|
|
|
if err != nil {
|
2016-09-02 10:28:29 +08:00
|
|
|
t.Log(err)
|
2016-08-30 11:51:31 +08:00
|
|
|
}
|
2016-09-05 16:37:15 +08:00
|
|
|
// Test write file to given path
|
|
|
|
err = file.WriteTo("./test/Workbook_2.xlsx")
|
2016-09-02 10:28:29 +08:00
|
|
|
if err != nil {
|
|
|
|
t.Log(err)
|
|
|
|
}
|
2016-09-05 16:37:15 +08:00
|
|
|
// Test write file to not exist directory
|
|
|
|
err = file.WriteTo("")
|
2016-09-02 10:28:29 +08:00
|
|
|
if err != nil {
|
|
|
|
t.Log(err)
|
|
|
|
}
|
2016-08-30 11:51:31 +08:00
|
|
|
|
|
|
|
// Test create a XLSX file
|
|
|
|
file2 := CreateFile()
|
2016-09-05 16:37:15 +08:00
|
|
|
file2.NewSheet(2, "XLSXSheet2")
|
|
|
|
file2.NewSheet(3, "XLSXSheet3")
|
|
|
|
file2.SetCellInt("Sheet2", "A23", 56)
|
|
|
|
file2.SetCellStr("SHEET1", "B20", "42")
|
|
|
|
file2.SetActiveSheet(0)
|
|
|
|
err = file2.WriteTo("./test/Workbook_3.xlsx")
|
2016-08-30 11:51:31 +08:00
|
|
|
if err != nil {
|
2016-09-02 10:28:29 +08:00
|
|
|
t.Log(err)
|
2016-08-30 11:51:31 +08:00
|
|
|
}
|
2016-08-30 21:54:28 +08:00
|
|
|
|
2016-09-06 21:20:24 +08:00
|
|
|
// Test open a XLSX file with given illegal path
|
|
|
|
_, err = OpenFile("./test/Workbook.xlsx")
|
|
|
|
if err != nil {
|
|
|
|
t.Log(err)
|
|
|
|
}
|
2016-08-30 11:51:31 +08:00
|
|
|
}
|