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
|
|
|
|
file, err := OpenFile("./test/Workbook1.xlsx")
|
|
|
|
if err != nil {
|
2016-09-02 10:28:29 +08:00
|
|
|
t.Log(err)
|
2016-08-30 11:51:31 +08:00
|
|
|
}
|
|
|
|
file = SetCellInt(file, "SHEET2", "B2", 100)
|
|
|
|
file = SetCellStr(file, "SHEET2", "C11", "Knowns")
|
|
|
|
file = NewSheet(file, 3, "TestSheet")
|
|
|
|
file = SetCellInt(file, "Sheet3", "A23", 10)
|
|
|
|
file = SetCellStr(file, "SHEET3", "b230", "10")
|
|
|
|
file = SetActiveSheet(file, 2)
|
|
|
|
if err != nil {
|
2016-09-02 10:28:29 +08:00
|
|
|
t.Log(err)
|
2016-08-30 11:51:31 +08:00
|
|
|
}
|
|
|
|
for i := 1; i <= 300; i++ {
|
2016-08-30 21:54:28 +08:00
|
|
|
file = SetCellStr(file, "SHEET3", "c"+strconv.Itoa(i), strconv.Itoa(i))
|
2016-08-30 11:51:31 +08:00
|
|
|
}
|
|
|
|
err = Save(file, "./test/Workbook_2.xlsx")
|
2016-09-02 10:28:29 +08:00
|
|
|
if err != nil {
|
|
|
|
t.Log(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test save to not exist directory
|
|
|
|
err = Save(file, "")
|
|
|
|
if err != nil {
|
|
|
|
t.Log(err)
|
|
|
|
}
|
2016-08-30 11:51:31 +08:00
|
|
|
|
|
|
|
// Test create a XLSX file
|
|
|
|
file2 := CreateFile()
|
2016-08-30 21:54:28 +08:00
|
|
|
file2 = NewSheet(file2, 2, "TestSheet2")
|
|
|
|
file2 = NewSheet(file2, 3, "TestSheet3")
|
2016-08-30 11:51:31 +08:00
|
|
|
file2 = SetCellInt(file2, "Sheet2", "A23", 10)
|
|
|
|
file2 = SetCellStr(file2, "SHEET1", "B20", "10")
|
2016-09-02 10:28:29 +08:00
|
|
|
file2 = SetActiveSheet(file2, 0)
|
2016-08-30 11:51:31 +08:00
|
|
|
err = Save(file2, "./test/Workbook_3.xlsx")
|
|
|
|
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
|
|
|
|
|
|
|
// Test read cell value
|
|
|
|
file, err = OpenFile("./test/Workbook1.xlsx")
|
|
|
|
if err != nil {
|
2016-09-02 10:28:29 +08:00
|
|
|
t.Log(err)
|
2016-08-30 21:54:28 +08:00
|
|
|
}
|
2016-09-02 19:41:14 +08:00
|
|
|
// Test given illegal rows number
|
2016-08-31 19:27:44 +08:00
|
|
|
GetCellValue(file, "Sheet2", "a-1")
|
2016-09-02 19:41:14 +08:00
|
|
|
// Test given lowercase column number
|
2016-08-30 21:54:28 +08:00
|
|
|
GetCellValue(file, "Sheet2", "a5")
|
2016-09-02 10:28:29 +08:00
|
|
|
GetCellValue(file, "Sheet2", "C11")
|
2016-08-30 21:54:28 +08:00
|
|
|
GetCellValue(file, "Sheet2", "D11")
|
|
|
|
GetCellValue(file, "Sheet2", "D12")
|
2016-09-02 19:41:14 +08:00
|
|
|
// Test given axis large than exists row
|
|
|
|
GetCellValue(file, "Sheet2", "E13")
|
2016-08-30 11:51:31 +08:00
|
|
|
}
|