2019-05-16 13:36:50 +08:00
|
|
|
package excelize
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2020-06-16 17:53:22 +08:00
|
|
|
"github.com/stretchr/testify/require"
|
2019-05-16 13:36:50 +08:00
|
|
|
)
|
|
|
|
|
2020-06-16 17:53:22 +08:00
|
|
|
func TestCols(t *testing.T) {
|
|
|
|
const sheet2 = "Sheet2"
|
|
|
|
|
|
|
|
f, err := OpenFile(filepath.Join("test", "Book1.xlsx"))
|
|
|
|
if !assert.NoError(t, err) {
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
|
|
|
|
cols, err := f.Cols(sheet2)
|
|
|
|
if !assert.NoError(t, err) {
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
|
|
|
|
var collectedRows [][]string
|
|
|
|
for cols.Next() {
|
|
|
|
rows, err := cols.Rows()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
collectedRows = append(collectedRows, trimSliceSpace(rows))
|
|
|
|
}
|
|
|
|
if !assert.NoError(t, cols.Error()) {
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
|
|
|
|
returnedColumns, err := f.GetCols(sheet2)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
for i := range returnedColumns {
|
|
|
|
returnedColumns[i] = trimSliceSpace(returnedColumns[i])
|
|
|
|
}
|
|
|
|
if !assert.Equal(t, collectedRows, returnedColumns) {
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
|
|
|
|
f = NewFile()
|
|
|
|
cells := []string{"C2", "C3", "C4"}
|
|
|
|
for _, cell := range cells {
|
|
|
|
assert.NoError(t, f.SetCellValue("Sheet1", cell, 1))
|
|
|
|
}
|
|
|
|
_, err = f.Rows("Sheet1")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
f.Sheet["xl/worksheets/sheet1.xml"] = &xlsxWorksheet{
|
|
|
|
Dimension: &xlsxDimension{
|
|
|
|
Ref: "C2:C4",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
_, err = f.Rows("Sheet1")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestColumnsIterator(t *testing.T) {
|
|
|
|
const (
|
|
|
|
sheet2 = "Sheet2"
|
2020-06-22 00:05:19 +08:00
|
|
|
expectedNumCol = 9
|
2020-06-16 17:53:22 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
f, err := OpenFile(filepath.Join("test", "Book1.xlsx"))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
cols, err := f.Cols(sheet2)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
var colCount int
|
|
|
|
for cols.Next() {
|
|
|
|
colCount++
|
|
|
|
require.True(t, colCount <= expectedNumCol, "colCount is greater than expected")
|
|
|
|
}
|
|
|
|
assert.Equal(t, expectedNumCol, colCount)
|
|
|
|
|
|
|
|
f = NewFile()
|
|
|
|
cells := []string{"C2", "C3", "C4", "D2", "D3", "D4"}
|
|
|
|
for _, cell := range cells {
|
|
|
|
assert.NoError(t, f.SetCellValue("Sheet1", cell, 1))
|
|
|
|
}
|
|
|
|
cols, err = f.Cols("Sheet1")
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
colCount = 0
|
|
|
|
for cols.Next() {
|
|
|
|
colCount++
|
2020-06-22 00:05:19 +08:00
|
|
|
require.True(t, colCount <= 4, "colCount is greater than expected")
|
2020-06-16 17:53:22 +08:00
|
|
|
}
|
2020-06-22 00:05:19 +08:00
|
|
|
assert.Equal(t, 4, colCount)
|
2020-06-16 17:53:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestColsError(t *testing.T) {
|
2020-06-22 00:05:19 +08:00
|
|
|
f, err := OpenFile(filepath.Join("test", "Book1.xlsx"))
|
|
|
|
if !assert.NoError(t, err) {
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
_, err = f.Cols("SheetN")
|
|
|
|
assert.EqualError(t, err, "sheet SheetN is not exist")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetColsError(t *testing.T) {
|
|
|
|
f, err := OpenFile(filepath.Join("test", "Book1.xlsx"))
|
2020-06-16 17:53:22 +08:00
|
|
|
if !assert.NoError(t, err) {
|
|
|
|
t.FailNow()
|
|
|
|
}
|
2020-06-22 00:05:19 +08:00
|
|
|
_, err = f.GetCols("SheetN")
|
2020-06-16 17:53:22 +08:00
|
|
|
assert.EqualError(t, err, "sheet SheetN is not exist")
|
2020-06-22 00:05:19 +08:00
|
|
|
|
|
|
|
f = NewFile()
|
|
|
|
delete(f.Sheet, "xl/worksheets/sheet1.xml")
|
|
|
|
f.XLSX["xl/worksheets/sheet1.xml"] = []byte(`<worksheet><sheetData><row r="A"><c r="2" t="str"><v>B</v></c></row></sheetData></worksheet>`)
|
|
|
|
f.checked = nil
|
|
|
|
_, err = f.GetCols("Sheet1")
|
|
|
|
assert.EqualError(t, err, `strconv.Atoi: parsing "A": invalid syntax`)
|
|
|
|
|
|
|
|
f = NewFile()
|
|
|
|
delete(f.Sheet, "xl/worksheets/sheet1.xml")
|
|
|
|
f.XLSX["xl/worksheets/sheet1.xml"] = []byte(`<worksheet><sheetData><row r="2"><c r="A" t="str"><v>B</v></c></row></sheetData></worksheet>`)
|
|
|
|
f.checked = nil
|
|
|
|
_, err = f.GetCols("Sheet1")
|
|
|
|
assert.EqualError(t, err, `cannot convert cell "A" to coordinates: invalid cell name "A"`)
|
|
|
|
|
|
|
|
f = NewFile()
|
|
|
|
cols, err := f.Cols("Sheet1")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
cols.totalRow = 2
|
|
|
|
cols.totalCol = 2
|
|
|
|
cols.curCol = 1
|
2020-06-22 00:14:56 +08:00
|
|
|
cols.sheetXML = []byte(`<worksheet><sheetData><row r="1"><c r="A" t="str"><v>A</v></c></row></sheetData></worksheet>`)
|
2020-06-22 00:05:19 +08:00
|
|
|
_, err = cols.Rows()
|
|
|
|
assert.EqualError(t, err, `cannot convert cell "A" to coordinates: invalid cell name "A"`)
|
2020-06-16 17:53:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestColsRows(t *testing.T) {
|
|
|
|
f := NewFile()
|
|
|
|
f.NewSheet("Sheet1")
|
|
|
|
|
|
|
|
cols, err := f.Cols("Sheet1")
|
2020-06-22 00:05:19 +08:00
|
|
|
assert.NoError(t, err)
|
2020-06-16 17:53:22 +08:00
|
|
|
|
|
|
|
assert.NoError(t, f.SetCellValue("Sheet1", "A1", 1))
|
|
|
|
f.Sheet["xl/worksheets/sheet1.xml"] = &xlsxWorksheet{
|
|
|
|
Dimension: &xlsxDimension{
|
|
|
|
Ref: "A1:A1",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-02-05 22:52:31 +08:00
|
|
|
f = NewFile()
|
|
|
|
f.XLSX["xl/worksheets/sheet1.xml"] = nil
|
|
|
|
cols, err = f.Cols("Sheet1")
|
|
|
|
if !assert.NoError(t, err) {
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
f = NewFile()
|
2020-06-16 17:53:22 +08:00
|
|
|
cols, err = f.Cols("Sheet1")
|
2021-02-05 22:52:31 +08:00
|
|
|
if !assert.NoError(t, err) {
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
_, err = cols.Rows()
|
2020-06-16 17:53:22 +08:00
|
|
|
assert.NoError(t, err)
|
2021-02-05 22:52:31 +08:00
|
|
|
cols.stashCol, cols.curCol = 0, 1
|
2020-06-16 17:53:22 +08:00
|
|
|
// Test if token is nil
|
2020-06-22 00:14:56 +08:00
|
|
|
cols.sheetXML = nil
|
2020-06-16 17:53:22 +08:00
|
|
|
_, err = cols.Rows()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
2019-05-16 13:36:50 +08:00
|
|
|
func TestColumnVisibility(t *testing.T) {
|
|
|
|
t.Run("TestBook1", func(t *testing.T) {
|
|
|
|
f, err := prepareTestBook1()
|
2019-09-24 21:53:19 +08:00
|
|
|
assert.NoError(t, err)
|
2019-05-16 13:36:50 +08:00
|
|
|
|
2020-01-22 06:42:44 +08:00
|
|
|
// Hide/display a column with SetColVisible
|
2019-05-16 13:36:50 +08:00
|
|
|
assert.NoError(t, f.SetColVisible("Sheet1", "F", false))
|
|
|
|
assert.NoError(t, f.SetColVisible("Sheet1", "F", true))
|
|
|
|
visible, err := f.GetColVisible("Sheet1", "F")
|
|
|
|
assert.Equal(t, true, visible)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2020-01-22 06:42:44 +08:00
|
|
|
// Test hiding a few columns SetColVisible(...false)...
|
|
|
|
assert.NoError(t, f.SetColVisible("Sheet1", "F:V", false))
|
|
|
|
visible, err = f.GetColVisible("Sheet1", "F")
|
|
|
|
assert.Equal(t, false, visible)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
visible, err = f.GetColVisible("Sheet1", "U")
|
|
|
|
assert.Equal(t, false, visible)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
visible, err = f.GetColVisible("Sheet1", "V")
|
|
|
|
assert.Equal(t, false, visible)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
// ...and displaying them back SetColVisible(...true)
|
2020-02-07 00:25:01 +08:00
|
|
|
assert.NoError(t, f.SetColVisible("Sheet1", "V:F", true))
|
2020-01-22 06:42:44 +08:00
|
|
|
visible, err = f.GetColVisible("Sheet1", "F")
|
|
|
|
assert.Equal(t, true, visible)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
visible, err = f.GetColVisible("Sheet1", "U")
|
|
|
|
assert.Equal(t, true, visible)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
visible, err = f.GetColVisible("Sheet1", "G")
|
|
|
|
assert.Equal(t, true, visible)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// Test get column visible on an inexistent worksheet.
|
2019-05-16 13:36:50 +08:00
|
|
|
_, err = f.GetColVisible("SheetN", "F")
|
|
|
|
assert.EqualError(t, err, "sheet SheetN is not exist")
|
|
|
|
|
2020-01-22 06:42:44 +08:00
|
|
|
// Test get column visible with illegal cell coordinates.
|
2019-05-16 13:36:50 +08:00
|
|
|
_, err = f.GetColVisible("Sheet1", "*")
|
|
|
|
assert.EqualError(t, err, `invalid column name "*"`)
|
|
|
|
assert.EqualError(t, f.SetColVisible("Sheet1", "*", false), `invalid column name "*"`)
|
|
|
|
|
|
|
|
f.NewSheet("Sheet3")
|
|
|
|
assert.NoError(t, f.SetColVisible("Sheet3", "E", false))
|
2020-02-07 00:25:01 +08:00
|
|
|
assert.EqualError(t, f.SetColVisible("Sheet1", "A:-1", true), "invalid column name \"-1\"")
|
2019-05-16 13:36:50 +08:00
|
|
|
assert.EqualError(t, f.SetColVisible("SheetN", "E", false), "sheet SheetN is not exist")
|
|
|
|
assert.NoError(t, f.SaveAs(filepath.Join("test", "TestColumnVisibility.xlsx")))
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("TestBook3", func(t *testing.T) {
|
|
|
|
f, err := prepareTestBook3()
|
2019-09-24 21:53:19 +08:00
|
|
|
assert.NoError(t, err)
|
2019-12-24 01:09:28 +08:00
|
|
|
visible, err := f.GetColVisible("Sheet1", "B")
|
|
|
|
assert.Equal(t, true, visible)
|
|
|
|
assert.NoError(t, err)
|
2019-05-16 13:36:50 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestOutlineLevel(t *testing.T) {
|
|
|
|
f := NewFile()
|
2019-12-24 01:09:28 +08:00
|
|
|
level, err := f.GetColOutlineLevel("Sheet1", "D")
|
|
|
|
assert.Equal(t, uint8(0), level)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2019-05-16 13:36:50 +08:00
|
|
|
f.NewSheet("Sheet2")
|
2019-09-24 21:53:19 +08:00
|
|
|
assert.NoError(t, f.SetColOutlineLevel("Sheet1", "D", 4))
|
2019-12-24 01:09:28 +08:00
|
|
|
|
|
|
|
level, err = f.GetColOutlineLevel("Sheet1", "D")
|
|
|
|
assert.Equal(t, uint8(4), level)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
level, err = f.GetColOutlineLevel("Shee2", "A")
|
|
|
|
assert.Equal(t, uint8(0), level)
|
|
|
|
assert.EqualError(t, err, "sheet Shee2 is not exist")
|
|
|
|
|
2019-09-24 21:53:19 +08:00
|
|
|
assert.NoError(t, f.SetColWidth("Sheet2", "A", "D", 13))
|
2020-09-18 22:20:58 +08:00
|
|
|
assert.EqualError(t, f.SetColWidth("Sheet2", "A", "D", MaxColumnWidth+1), "the width of the column must be smaller than or equal to 255 characters")
|
|
|
|
|
2019-09-24 21:53:19 +08:00
|
|
|
assert.NoError(t, f.SetColOutlineLevel("Sheet2", "B", 2))
|
|
|
|
assert.NoError(t, f.SetRowOutlineLevel("Sheet1", 2, 7))
|
|
|
|
assert.EqualError(t, f.SetColOutlineLevel("Sheet1", "D", 8), "invalid outline level")
|
|
|
|
assert.EqualError(t, f.SetRowOutlineLevel("Sheet1", 2, 8), "invalid outline level")
|
2019-10-26 20:55:24 +08:00
|
|
|
// Test set row outline level on not exists worksheet.
|
|
|
|
assert.EqualError(t, f.SetRowOutlineLevel("SheetN", 1, 4), "sheet SheetN is not exist")
|
|
|
|
// Test get row outline level on not exists worksheet.
|
2019-12-24 01:09:28 +08:00
|
|
|
_, err = f.GetRowOutlineLevel("SheetN", 1)
|
2019-10-26 20:55:24 +08:00
|
|
|
assert.EqualError(t, err, "sheet SheetN is not exist")
|
2019-05-16 13:36:50 +08:00
|
|
|
|
|
|
|
// Test set and get column outline level with illegal cell coordinates.
|
|
|
|
assert.EqualError(t, f.SetColOutlineLevel("Sheet1", "*", 1), `invalid column name "*"`)
|
2019-10-26 20:55:24 +08:00
|
|
|
_, err = f.GetColOutlineLevel("Sheet1", "*")
|
2019-05-16 13:36:50 +08:00
|
|
|
assert.EqualError(t, err, `invalid column name "*"`)
|
|
|
|
|
|
|
|
// Test set column outline level on not exists worksheet.
|
|
|
|
assert.EqualError(t, f.SetColOutlineLevel("SheetN", "E", 2), "sheet SheetN is not exist")
|
|
|
|
|
|
|
|
assert.EqualError(t, f.SetRowOutlineLevel("Sheet1", 0, 1), "invalid row number 0")
|
2019-12-24 01:09:28 +08:00
|
|
|
level, err = f.GetRowOutlineLevel("Sheet1", 2)
|
2019-05-16 13:36:50 +08:00
|
|
|
assert.NoError(t, err)
|
2019-09-24 21:53:19 +08:00
|
|
|
assert.Equal(t, uint8(7), level)
|
2019-05-16 13:36:50 +08:00
|
|
|
|
|
|
|
_, err = f.GetRowOutlineLevel("Sheet1", 0)
|
|
|
|
assert.EqualError(t, err, `invalid row number 0`)
|
|
|
|
|
|
|
|
level, err = f.GetRowOutlineLevel("Sheet1", 10)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, uint8(0), level)
|
|
|
|
|
2019-09-24 21:53:19 +08:00
|
|
|
assert.NoError(t, f.SaveAs(filepath.Join("test", "TestOutlineLevel.xlsx")))
|
2019-05-16 13:36:50 +08:00
|
|
|
|
|
|
|
f, err = OpenFile(filepath.Join("test", "Book1.xlsx"))
|
2019-09-24 21:53:19 +08:00
|
|
|
assert.NoError(t, err)
|
2019-12-24 01:09:28 +08:00
|
|
|
assert.NoError(t, f.SetColOutlineLevel("Sheet2", "B", 2))
|
2019-05-16 13:36:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSetColStyle(t *testing.T) {
|
|
|
|
f := NewFile()
|
|
|
|
style, err := f.NewStyle(`{"fill":{"type":"pattern","color":["#94d3a2"],"pattern":1}}`)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
// Test set column style on not exists worksheet.
|
|
|
|
assert.EqualError(t, f.SetColStyle("SheetN", "E", style), "sheet SheetN is not exist")
|
|
|
|
// Test set column style with illegal cell coordinates.
|
|
|
|
assert.EqualError(t, f.SetColStyle("Sheet1", "*", style), `invalid column name "*"`)
|
|
|
|
assert.EqualError(t, f.SetColStyle("Sheet1", "A:*", style), `invalid column name "*"`)
|
|
|
|
|
|
|
|
assert.NoError(t, f.SetColStyle("Sheet1", "B", style))
|
|
|
|
// Test set column style with already exists column with style.
|
|
|
|
assert.NoError(t, f.SetColStyle("Sheet1", "B", style))
|
|
|
|
assert.NoError(t, f.SetColStyle("Sheet1", "D:C", style))
|
|
|
|
assert.NoError(t, f.SaveAs(filepath.Join("test", "TestSetColStyle.xlsx")))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestColWidth(t *testing.T) {
|
|
|
|
f := NewFile()
|
2019-12-24 01:09:28 +08:00
|
|
|
assert.NoError(t, f.SetColWidth("Sheet1", "B", "A", 12))
|
|
|
|
assert.NoError(t, f.SetColWidth("Sheet1", "A", "B", 12))
|
|
|
|
width, err := f.GetColWidth("Sheet1", "A")
|
|
|
|
assert.Equal(t, float64(12), width)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
width, err = f.GetColWidth("Sheet1", "C")
|
|
|
|
assert.Equal(t, float64(64), width)
|
|
|
|
assert.NoError(t, err)
|
2019-05-16 13:36:50 +08:00
|
|
|
|
|
|
|
// Test set and get column width with illegal cell coordinates.
|
2019-12-24 01:09:28 +08:00
|
|
|
width, err = f.GetColWidth("Sheet1", "*")
|
|
|
|
assert.Equal(t, float64(64), width)
|
2019-05-16 13:36:50 +08:00
|
|
|
assert.EqualError(t, err, `invalid column name "*"`)
|
|
|
|
assert.EqualError(t, f.SetColWidth("Sheet1", "*", "B", 1), `invalid column name "*"`)
|
|
|
|
assert.EqualError(t, f.SetColWidth("Sheet1", "A", "*", 1), `invalid column name "*"`)
|
|
|
|
|
|
|
|
// Test set column width on not exists worksheet.
|
|
|
|
assert.EqualError(t, f.SetColWidth("SheetN", "B", "A", 12), "sheet SheetN is not exist")
|
|
|
|
|
|
|
|
// Test get column width on not exists worksheet.
|
|
|
|
_, err = f.GetColWidth("SheetN", "A")
|
|
|
|
assert.EqualError(t, err, "sheet SheetN is not exist")
|
|
|
|
|
|
|
|
assert.NoError(t, f.SaveAs(filepath.Join("test", "TestColWidth.xlsx")))
|
|
|
|
convertRowHeightToPixels(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestInsertCol(t *testing.T) {
|
|
|
|
f := NewFile()
|
2020-04-23 02:01:14 +08:00
|
|
|
sheet1 := f.GetSheetName(0)
|
2019-05-16 13:36:50 +08:00
|
|
|
|
|
|
|
fillCells(f, sheet1, 10, 10)
|
|
|
|
|
2019-12-24 01:09:28 +08:00
|
|
|
assert.NoError(t, f.SetCellHyperLink(sheet1, "A5", "https://github.com/360EntSecGroup-Skylar/excelize", "External"))
|
|
|
|
assert.NoError(t, f.MergeCell(sheet1, "A1", "C3"))
|
2019-05-16 13:36:50 +08:00
|
|
|
|
2019-09-24 21:53:19 +08:00
|
|
|
assert.NoError(t, f.AutoFilter(sheet1, "A2", "B2", `{"column":"B","expression":"x != blanks"}`))
|
2019-05-16 13:36:50 +08:00
|
|
|
assert.NoError(t, f.InsertCol(sheet1, "A"))
|
|
|
|
|
|
|
|
// Test insert column with illegal cell coordinates.
|
|
|
|
assert.EqualError(t, f.InsertCol("Sheet1", "*"), `invalid column name "*"`)
|
|
|
|
|
|
|
|
assert.NoError(t, f.SaveAs(filepath.Join("test", "TestInsertCol.xlsx")))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRemoveCol(t *testing.T) {
|
|
|
|
f := NewFile()
|
2020-04-23 02:01:14 +08:00
|
|
|
sheet1 := f.GetSheetName(0)
|
2019-05-16 13:36:50 +08:00
|
|
|
|
|
|
|
fillCells(f, sheet1, 10, 15)
|
|
|
|
|
2019-12-24 01:09:28 +08:00
|
|
|
assert.NoError(t, f.SetCellHyperLink(sheet1, "A5", "https://github.com/360EntSecGroup-Skylar/excelize", "External"))
|
|
|
|
assert.NoError(t, f.SetCellHyperLink(sheet1, "C5", "https://github.com", "External"))
|
2019-05-16 13:36:50 +08:00
|
|
|
|
2019-12-24 01:09:28 +08:00
|
|
|
assert.NoError(t, f.MergeCell(sheet1, "A1", "B1"))
|
|
|
|
assert.NoError(t, f.MergeCell(sheet1, "A2", "B2"))
|
2019-05-16 13:36:50 +08:00
|
|
|
|
|
|
|
assert.NoError(t, f.RemoveCol(sheet1, "A"))
|
|
|
|
assert.NoError(t, f.RemoveCol(sheet1, "A"))
|
|
|
|
|
|
|
|
// Test remove column with illegal cell coordinates.
|
|
|
|
assert.EqualError(t, f.RemoveCol("Sheet1", "*"), `invalid column name "*"`)
|
|
|
|
|
|
|
|
// Test remove column on not exists worksheet.
|
|
|
|
assert.EqualError(t, f.RemoveCol("SheetN", "B"), "sheet SheetN is not exist")
|
|
|
|
|
|
|
|
assert.NoError(t, f.SaveAs(filepath.Join("test", "TestRemoveCol.xlsx")))
|
|
|
|
}
|
2020-10-18 00:01:33 +08:00
|
|
|
|
|
|
|
func TestConvertColWidthToPixels(t *testing.T) {
|
|
|
|
assert.Equal(t, -11.0, convertColWidthToPixels(-1))
|
|
|
|
}
|