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()
|
|
|
|
}
|
2021-09-18 23:20:24 +08:00
|
|
|
assert.NoError(t, f.Close())
|
2020-06-16 17:53:22 +08:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2021-07-05 00:03:56 +08:00
|
|
|
f.Sheet.Store("xl/worksheets/sheet1.xml", &xlsxWorksheet{
|
2020-06-16 17:53:22 +08:00
|
|
|
Dimension: &xlsxDimension{
|
|
|
|
Ref: "C2:C4",
|
|
|
|
},
|
2021-07-05 00:03:56 +08:00
|
|
|
})
|
2020-06-16 17:53:22 +08:00
|
|
|
_, err = f.Rows("Sheet1")
|
|
|
|
assert.NoError(t, err)
|
2022-11-12 00:02:11 +08:00
|
|
|
|
This closes #1425, breaking changes for sheet name (#1426)
- Checking and return error for invalid sheet name instead of trim invalid characters
- Add error return for the 4 functions: `DeleteSheet`, `GetSheetIndex`, `GetSheetVisible` and `SetSheetName`
- Export new error 4 constants: `ErrSheetNameBlank`, `ErrSheetNameInvalid`, `ErrSheetNameLength` and `ErrSheetNameSingleQuote`
- Rename exported error constant `ErrExistsWorksheet` to `ErrExistsSheet`
- Update unit tests for 90 functions: `AddChart`, `AddChartSheet`, `AddComment`, `AddDataValidation`, `AddPicture`, `AddPictureFromBytes`, `AddPivotTable`, `AddShape`, `AddSparkline`, `AddTable`, `AutoFilter`, `CalcCellValue`, `Cols`, `DeleteChart`, `DeleteComment`, `DeleteDataValidation`, `DeletePicture`, `DeleteSheet`, `DuplicateRow`, `DuplicateRowTo`, `GetCellFormula`, `GetCellHyperLink`, `GetCellRichText`, `GetCellStyle`, `GetCellType`, `GetCellValue`, `GetColOutlineLevel`, `GetCols`, `GetColStyle`, `GetColVisible`, `GetColWidth`, `GetConditionalFormats`, `GetDataValidations`, `GetMergeCells`, `GetPageLayout`, `GetPageMargins`, `GetPicture`, `GetRowHeight`, `GetRowOutlineLevel`, `GetRows`, `GetRowVisible`, `GetSheetIndex`, `GetSheetProps`, `GetSheetVisible`, `GroupSheets`, `InsertCol`, `InsertPageBreak`, `InsertRows`, `MergeCell`, `NewSheet`, `NewStreamWriter`, `ProtectSheet`, `RemoveCol`, `RemovePageBreak`, `RemoveRow`, `Rows`, `SearchSheet`, `SetCellBool`, `SetCellDefault`, `SetCellFloat`, `SetCellFormula`, `SetCellHyperLink`, `SetCellInt`, `SetCellRichText`, `SetCellStr`, `SetCellStyle`, `SetCellValue`, `SetColOutlineLevel`, `SetColStyle`, `SetColVisible`, `SetColWidth`, `SetConditionalFormat`, `SetHeaderFooter`, `SetPageLayout`, `SetPageMargins`, `SetPanes`, `SetRowHeight`, `SetRowOutlineLevel`, `SetRowStyle`, `SetRowVisible`, `SetSheetBackground`, `SetSheetBackgroundFromBytes`, `SetSheetCol`, `SetSheetName`, `SetSheetProps`, `SetSheetRow`, `SetSheetVisible`, `UnmergeCell`, `UnprotectSheet` and
`UnsetConditionalFormat`
- Update documentation of the set style functions
Co-authored-by: guoweikuang <weikuang.guo@shopee.com>
2022-12-23 00:54:40 +08:00
|
|
|
// Test columns iterator with invalid sheet name
|
|
|
|
_, err = f.Cols("Sheet:1")
|
|
|
|
assert.EqualError(t, err, ErrSheetNameInvalid.Error())
|
|
|
|
// Test get columns cells with invalid sheet name
|
|
|
|
_, err = f.GetCols("Sheet:1")
|
|
|
|
assert.EqualError(t, err, ErrSheetNameInvalid.Error())
|
|
|
|
// Test columns iterator with unsupported charset shared strings table
|
2022-11-12 00:02:11 +08:00
|
|
|
f.SharedStrings = nil
|
|
|
|
f.Pkg.Store(defaultXMLPathSharedStrings, MacintoshCyrillicCharset)
|
|
|
|
cols, err = f.Cols("Sheet1")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
cols.Next()
|
|
|
|
_, err = cols.Rows()
|
|
|
|
assert.EqualError(t, err, "XML syntax error on line 1: invalid UTF-8")
|
2020-06-16 17:53:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestColumnsIterator(t *testing.T) {
|
2021-11-05 00:01:34 +08:00
|
|
|
sheetName, colCount, expectedNumCol := "Sheet2", 0, 9
|
2020-06-16 17:53:22 +08:00
|
|
|
f, err := OpenFile(filepath.Join("test", "Book1.xlsx"))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-11-05 00:01:34 +08:00
|
|
|
cols, err := f.Cols(sheetName)
|
2020-06-16 17:53:22 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
for cols.Next() {
|
|
|
|
colCount++
|
|
|
|
require.True(t, colCount <= expectedNumCol, "colCount is greater than expected")
|
|
|
|
}
|
|
|
|
assert.Equal(t, expectedNumCol, colCount)
|
2021-09-18 23:20:24 +08:00
|
|
|
assert.NoError(t, f.Close())
|
2020-06-16 17:53:22 +08:00
|
|
|
|
2021-11-05 00:01:34 +08:00
|
|
|
f, sheetName, colCount, expectedNumCol = NewFile(), "Sheet1", 0, 4
|
2020-06-16 17:53:22 +08:00
|
|
|
cells := []string{"C2", "C3", "C4", "D2", "D3", "D4"}
|
|
|
|
for _, cell := range cells {
|
2021-11-05 00:01:34 +08:00
|
|
|
assert.NoError(t, f.SetCellValue(sheetName, cell, 1))
|
2020-06-16 17:53:22 +08:00
|
|
|
}
|
2021-11-05 00:01:34 +08:00
|
|
|
cols, err = f.Cols(sheetName)
|
2020-06-16 17:53:22 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
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
|
|
|
}
|
2021-11-05 00:01:34 +08:00
|
|
|
assert.Equal(t, expectedNumCol, 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")
|
2022-08-28 00:16:41 +08:00
|
|
|
assert.EqualError(t, err, "sheet SheetN does not exist")
|
2021-09-18 23:20:24 +08:00
|
|
|
assert.NoError(t, f.Close())
|
2020-06-22 00:05:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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")
|
2022-08-28 00:16:41 +08:00
|
|
|
assert.EqualError(t, err, "sheet SheetN does not exist")
|
2021-09-18 23:20:24 +08:00
|
|
|
assert.NoError(t, f.Close())
|
2020-06-22 00:05:19 +08:00
|
|
|
|
|
|
|
f = NewFile()
|
2021-07-05 00:03:56 +08:00
|
|
|
f.Sheet.Delete("xl/worksheets/sheet1.xml")
|
2022-10-25 10:24:45 +08:00
|
|
|
f.Pkg.Store("xl/worksheets/sheet1.xml", []byte(`<worksheet><sheetData><row r="A"><c r="2" t="inlineStr"><is><t>B</t></is></c></row></sheetData></worksheet>`))
|
2020-06-22 00:05:19 +08:00
|
|
|
f.checked = nil
|
|
|
|
_, err = f.GetCols("Sheet1")
|
|
|
|
assert.EqualError(t, err, `strconv.Atoi: parsing "A": invalid syntax`)
|
|
|
|
|
2022-10-25 10:24:45 +08:00
|
|
|
f.Pkg.Store("xl/worksheets/sheet1.xml", []byte(`<worksheet><sheetData><row r="2"><c r="A" t="inlineStr"><is><t>B</t></is></c></row></sheetData></worksheet>`))
|
2020-06-22 00:05:19 +08:00
|
|
|
_, err = f.GetCols("Sheet1")
|
2021-12-07 00:26:53 +08:00
|
|
|
assert.EqualError(t, err, newCellNameToCoordinatesError("A", newInvalidCellNameError("A")).Error())
|
2020-06-22 00:05:19 +08:00
|
|
|
|
|
|
|
f = NewFile()
|
|
|
|
cols, err := f.Cols("Sheet1")
|
|
|
|
assert.NoError(t, err)
|
2021-11-05 00:01:34 +08:00
|
|
|
cols.totalRows = 2
|
|
|
|
cols.totalCols = 2
|
2020-06-22 00:05:19 +08:00
|
|
|
cols.curCol = 1
|
2022-10-25 10:24:45 +08:00
|
|
|
cols.sheetXML = []byte(`<worksheet><sheetData><row r="1"><c r="A" t="inlineStr"><is><t>A</t></is></c></row></sheetData></worksheet>`)
|
2020-06-22 00:05:19 +08:00
|
|
|
_, err = cols.Rows()
|
2021-12-07 00:26:53 +08:00
|
|
|
assert.EqualError(t, err, newCellNameToCoordinatesError("A", newInvalidCellNameError("A")).Error())
|
2022-01-19 00:51:09 +08:00
|
|
|
|
|
|
|
f.Pkg.Store("xl/worksheets/sheet1.xml", nil)
|
|
|
|
f.Sheet.Store("xl/worksheets/sheet1.xml", nil)
|
|
|
|
_, err = f.Cols("Sheet1")
|
|
|
|
assert.NoError(t, err)
|
2020-06-16 17:53:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestColsRows(t *testing.T) {
|
|
|
|
f := NewFile()
|
|
|
|
|
2021-02-15 00:09:35 +08:00
|
|
|
_, 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))
|
2021-07-05 00:03:56 +08:00
|
|
|
f.Sheet.Store("xl/worksheets/sheet1.xml", &xlsxWorksheet{
|
2020-06-16 17:53:22 +08:00
|
|
|
Dimension: &xlsxDimension{
|
|
|
|
Ref: "A1:A1",
|
|
|
|
},
|
2021-07-05 00:03:56 +08:00
|
|
|
})
|
2020-06-16 17:53:22 +08:00
|
|
|
|
2021-02-05 22:52:31 +08:00
|
|
|
f = NewFile()
|
2021-07-05 00:03:56 +08:00
|
|
|
f.Pkg.Store("xl/worksheets/sheet1.xml", nil)
|
2021-02-15 00:09:35 +08:00
|
|
|
_, err = f.Cols("Sheet1")
|
2021-02-05 22:52:31 +08:00
|
|
|
if !assert.NoError(t, err) {
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
f = NewFile()
|
2021-02-15 00:09:35 +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)
|
|
|
|
|
This closes #1425, breaking changes for sheet name (#1426)
- Checking and return error for invalid sheet name instead of trim invalid characters
- Add error return for the 4 functions: `DeleteSheet`, `GetSheetIndex`, `GetSheetVisible` and `SetSheetName`
- Export new error 4 constants: `ErrSheetNameBlank`, `ErrSheetNameInvalid`, `ErrSheetNameLength` and `ErrSheetNameSingleQuote`
- Rename exported error constant `ErrExistsWorksheet` to `ErrExistsSheet`
- Update unit tests for 90 functions: `AddChart`, `AddChartSheet`, `AddComment`, `AddDataValidation`, `AddPicture`, `AddPictureFromBytes`, `AddPivotTable`, `AddShape`, `AddSparkline`, `AddTable`, `AutoFilter`, `CalcCellValue`, `Cols`, `DeleteChart`, `DeleteComment`, `DeleteDataValidation`, `DeletePicture`, `DeleteSheet`, `DuplicateRow`, `DuplicateRowTo`, `GetCellFormula`, `GetCellHyperLink`, `GetCellRichText`, `GetCellStyle`, `GetCellType`, `GetCellValue`, `GetColOutlineLevel`, `GetCols`, `GetColStyle`, `GetColVisible`, `GetColWidth`, `GetConditionalFormats`, `GetDataValidations`, `GetMergeCells`, `GetPageLayout`, `GetPageMargins`, `GetPicture`, `GetRowHeight`, `GetRowOutlineLevel`, `GetRows`, `GetRowVisible`, `GetSheetIndex`, `GetSheetProps`, `GetSheetVisible`, `GroupSheets`, `InsertCol`, `InsertPageBreak`, `InsertRows`, `MergeCell`, `NewSheet`, `NewStreamWriter`, `ProtectSheet`, `RemoveCol`, `RemovePageBreak`, `RemoveRow`, `Rows`, `SearchSheet`, `SetCellBool`, `SetCellDefault`, `SetCellFloat`, `SetCellFormula`, `SetCellHyperLink`, `SetCellInt`, `SetCellRichText`, `SetCellStr`, `SetCellStyle`, `SetCellValue`, `SetColOutlineLevel`, `SetColStyle`, `SetColVisible`, `SetColWidth`, `SetConditionalFormat`, `SetHeaderFooter`, `SetPageLayout`, `SetPageMargins`, `SetPanes`, `SetRowHeight`, `SetRowOutlineLevel`, `SetRowStyle`, `SetRowVisible`, `SetSheetBackground`, `SetSheetBackgroundFromBytes`, `SetSheetCol`, `SetSheetName`, `SetSheetProps`, `SetSheetRow`, `SetSheetVisible`, `UnmergeCell`, `UnprotectSheet` and
`UnsetConditionalFormat`
- Update documentation of the set style functions
Co-authored-by: guoweikuang <weikuang.guo@shopee.com>
2022-12-23 00:54:40 +08:00
|
|
|
// Test get column visible on an inexistent worksheet
|
2019-05-16 13:36:50 +08:00
|
|
|
_, err = f.GetColVisible("SheetN", "F")
|
2022-08-28 00:16:41 +08:00
|
|
|
assert.EqualError(t, err, "sheet SheetN does not exist")
|
This closes #1425, breaking changes for sheet name (#1426)
- Checking and return error for invalid sheet name instead of trim invalid characters
- Add error return for the 4 functions: `DeleteSheet`, `GetSheetIndex`, `GetSheetVisible` and `SetSheetName`
- Export new error 4 constants: `ErrSheetNameBlank`, `ErrSheetNameInvalid`, `ErrSheetNameLength` and `ErrSheetNameSingleQuote`
- Rename exported error constant `ErrExistsWorksheet` to `ErrExistsSheet`
- Update unit tests for 90 functions: `AddChart`, `AddChartSheet`, `AddComment`, `AddDataValidation`, `AddPicture`, `AddPictureFromBytes`, `AddPivotTable`, `AddShape`, `AddSparkline`, `AddTable`, `AutoFilter`, `CalcCellValue`, `Cols`, `DeleteChart`, `DeleteComment`, `DeleteDataValidation`, `DeletePicture`, `DeleteSheet`, `DuplicateRow`, `DuplicateRowTo`, `GetCellFormula`, `GetCellHyperLink`, `GetCellRichText`, `GetCellStyle`, `GetCellType`, `GetCellValue`, `GetColOutlineLevel`, `GetCols`, `GetColStyle`, `GetColVisible`, `GetColWidth`, `GetConditionalFormats`, `GetDataValidations`, `GetMergeCells`, `GetPageLayout`, `GetPageMargins`, `GetPicture`, `GetRowHeight`, `GetRowOutlineLevel`, `GetRows`, `GetRowVisible`, `GetSheetIndex`, `GetSheetProps`, `GetSheetVisible`, `GroupSheets`, `InsertCol`, `InsertPageBreak`, `InsertRows`, `MergeCell`, `NewSheet`, `NewStreamWriter`, `ProtectSheet`, `RemoveCol`, `RemovePageBreak`, `RemoveRow`, `Rows`, `SearchSheet`, `SetCellBool`, `SetCellDefault`, `SetCellFloat`, `SetCellFormula`, `SetCellHyperLink`, `SetCellInt`, `SetCellRichText`, `SetCellStr`, `SetCellStyle`, `SetCellValue`, `SetColOutlineLevel`, `SetColStyle`, `SetColVisible`, `SetColWidth`, `SetConditionalFormat`, `SetHeaderFooter`, `SetPageLayout`, `SetPageMargins`, `SetPanes`, `SetRowHeight`, `SetRowOutlineLevel`, `SetRowStyle`, `SetRowVisible`, `SetSheetBackground`, `SetSheetBackgroundFromBytes`, `SetSheetCol`, `SetSheetName`, `SetSheetProps`, `SetSheetRow`, `SetSheetVisible`, `UnmergeCell`, `UnprotectSheet` and
`UnsetConditionalFormat`
- Update documentation of the set style functions
Co-authored-by: guoweikuang <weikuang.guo@shopee.com>
2022-12-23 00:54:40 +08:00
|
|
|
// Test get column visible with invalid sheet name
|
|
|
|
_, err = f.GetColVisible("Sheet:1", "F")
|
|
|
|
assert.EqualError(t, err, ErrSheetNameInvalid.Error())
|
|
|
|
// Test get column visible with illegal cell reference
|
2019-05-16 13:36:50 +08:00
|
|
|
_, err = f.GetColVisible("Sheet1", "*")
|
2021-12-07 00:26:53 +08:00
|
|
|
assert.EqualError(t, err, newInvalidColumnNameError("*").Error())
|
|
|
|
assert.EqualError(t, f.SetColVisible("Sheet1", "*", false), newInvalidColumnNameError("*").Error())
|
This closes #1425, breaking changes for sheet name (#1426)
- Checking and return error for invalid sheet name instead of trim invalid characters
- Add error return for the 4 functions: `DeleteSheet`, `GetSheetIndex`, `GetSheetVisible` and `SetSheetName`
- Export new error 4 constants: `ErrSheetNameBlank`, `ErrSheetNameInvalid`, `ErrSheetNameLength` and `ErrSheetNameSingleQuote`
- Rename exported error constant `ErrExistsWorksheet` to `ErrExistsSheet`
- Update unit tests for 90 functions: `AddChart`, `AddChartSheet`, `AddComment`, `AddDataValidation`, `AddPicture`, `AddPictureFromBytes`, `AddPivotTable`, `AddShape`, `AddSparkline`, `AddTable`, `AutoFilter`, `CalcCellValue`, `Cols`, `DeleteChart`, `DeleteComment`, `DeleteDataValidation`, `DeletePicture`, `DeleteSheet`, `DuplicateRow`, `DuplicateRowTo`, `GetCellFormula`, `GetCellHyperLink`, `GetCellRichText`, `GetCellStyle`, `GetCellType`, `GetCellValue`, `GetColOutlineLevel`, `GetCols`, `GetColStyle`, `GetColVisible`, `GetColWidth`, `GetConditionalFormats`, `GetDataValidations`, `GetMergeCells`, `GetPageLayout`, `GetPageMargins`, `GetPicture`, `GetRowHeight`, `GetRowOutlineLevel`, `GetRows`, `GetRowVisible`, `GetSheetIndex`, `GetSheetProps`, `GetSheetVisible`, `GroupSheets`, `InsertCol`, `InsertPageBreak`, `InsertRows`, `MergeCell`, `NewSheet`, `NewStreamWriter`, `ProtectSheet`, `RemoveCol`, `RemovePageBreak`, `RemoveRow`, `Rows`, `SearchSheet`, `SetCellBool`, `SetCellDefault`, `SetCellFloat`, `SetCellFormula`, `SetCellHyperLink`, `SetCellInt`, `SetCellRichText`, `SetCellStr`, `SetCellStyle`, `SetCellValue`, `SetColOutlineLevel`, `SetColStyle`, `SetColVisible`, `SetColWidth`, `SetConditionalFormat`, `SetHeaderFooter`, `SetPageLayout`, `SetPageMargins`, `SetPanes`, `SetRowHeight`, `SetRowOutlineLevel`, `SetRowStyle`, `SetRowVisible`, `SetSheetBackground`, `SetSheetBackgroundFromBytes`, `SetSheetCol`, `SetSheetName`, `SetSheetProps`, `SetSheetRow`, `SetSheetVisible`, `UnmergeCell`, `UnprotectSheet` and
`UnsetConditionalFormat`
- Update documentation of the set style functions
Co-authored-by: guoweikuang <weikuang.guo@shopee.com>
2022-12-23 00:54:40 +08:00
|
|
|
// Test set column visible with invalid sheet name
|
|
|
|
assert.EqualError(t, f.SetColVisible("Sheet:1", "A", false), ErrSheetNameInvalid.Error())
|
2019-05-16 13:36:50 +08:00
|
|
|
|
Breaking change: changed the function signature for 11 exported functions
* Change
`func (f *File) NewConditionalStyle(style string) (int, error)`
to
`func (f *File) NewConditionalStyle(style *Style) (int, error)`
* Change
`func (f *File) NewStyle(style interface{}) (int, error)`
to
`func (f *File) NewStyle(style *Style) (int, error)`
* Change
`func (f *File) AddChart(sheet, cell, opts string, combo ...string) error`
to
`func (f *File) AddChart(sheet, cell string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddChartSheet(sheet, opts string, combo ...string) error`
to
`func (f *File) AddChartSheet(sheet string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddShape(sheet, cell, opts string) error`
to
`func (f *File) AddShape(sheet, cell string, opts *Shape) error`
* Change
`func (f *File) AddPictureFromBytes(sheet, cell, opts, name, extension string, file []byte) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *PictureOptions) error`
* Change
`func (f *File) AddTable(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AddTable(sheet, reference string, opts *TableOptions) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) AutoFilter(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AutoFilter(sheet, reference string, opts *AutoFilterOptions) error`
* Change
`func (f *File) SetPanes(sheet, panes string) error`
to
`func (f *File) SetPanes(sheet string, panes *Panes) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) SetConditionalFormat(sheet, reference, opts string) error`
to
`func (f *File) SetConditionalFormat(sheet, reference string, opts []ConditionalFormatOptions) error`
* Add exported types:
* AutoFilterListOptions
* AutoFilterOptions
* Chart
* ChartAxis
* ChartDimension
* ChartLegend
* ChartLine
* ChartMarker
* ChartPlotArea
* ChartSeries
* ChartTitle
* ConditionalFormatOptions
* PaneOptions
* Panes
* PictureOptions
* Shape
* ShapeColor
* ShapeLine
* ShapeParagraph
* TableOptions
* This added support for set sheet visible as very hidden
* Return error when missing required parameters for set defined name
* Update unit test and comments
2022-12-30 00:50:08 +08:00
|
|
|
_, err = f.NewSheet("Sheet3")
|
|
|
|
assert.NoError(t, err)
|
2019-05-16 13:36:50 +08:00
|
|
|
assert.NoError(t, f.SetColVisible("Sheet3", "E", false))
|
2021-12-07 00:26:53 +08:00
|
|
|
assert.EqualError(t, f.SetColVisible("Sheet1", "A:-1", true), newInvalidColumnNameError("-1").Error())
|
2022-08-28 00:16:41 +08:00
|
|
|
assert.EqualError(t, f.SetColVisible("SheetN", "E", false), "sheet SheetN does not exist")
|
2019-05-16 13:36:50 +08:00
|
|
|
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)
|
|
|
|
|
Breaking change: changed the function signature for 11 exported functions
* Change
`func (f *File) NewConditionalStyle(style string) (int, error)`
to
`func (f *File) NewConditionalStyle(style *Style) (int, error)`
* Change
`func (f *File) NewStyle(style interface{}) (int, error)`
to
`func (f *File) NewStyle(style *Style) (int, error)`
* Change
`func (f *File) AddChart(sheet, cell, opts string, combo ...string) error`
to
`func (f *File) AddChart(sheet, cell string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddChartSheet(sheet, opts string, combo ...string) error`
to
`func (f *File) AddChartSheet(sheet string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddShape(sheet, cell, opts string) error`
to
`func (f *File) AddShape(sheet, cell string, opts *Shape) error`
* Change
`func (f *File) AddPictureFromBytes(sheet, cell, opts, name, extension string, file []byte) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *PictureOptions) error`
* Change
`func (f *File) AddTable(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AddTable(sheet, reference string, opts *TableOptions) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) AutoFilter(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AutoFilter(sheet, reference string, opts *AutoFilterOptions) error`
* Change
`func (f *File) SetPanes(sheet, panes string) error`
to
`func (f *File) SetPanes(sheet string, panes *Panes) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) SetConditionalFormat(sheet, reference, opts string) error`
to
`func (f *File) SetConditionalFormat(sheet, reference string, opts []ConditionalFormatOptions) error`
* Add exported types:
* AutoFilterListOptions
* AutoFilterOptions
* Chart
* ChartAxis
* ChartDimension
* ChartLegend
* ChartLine
* ChartMarker
* ChartPlotArea
* ChartSeries
* ChartTitle
* ConditionalFormatOptions
* PaneOptions
* Panes
* PictureOptions
* Shape
* ShapeColor
* ShapeLine
* ShapeParagraph
* TableOptions
* This added support for set sheet visible as very hidden
* Return error when missing required parameters for set defined name
* Update unit test and comments
2022-12-30 00:50:08 +08:00
|
|
|
_, err = f.NewSheet("Sheet2")
|
|
|
|
assert.NoError(t, err)
|
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)
|
|
|
|
|
2021-11-14 00:17:31 +08:00
|
|
|
level, err = f.GetColOutlineLevel("SheetN", "A")
|
2019-12-24 01:09:28 +08:00
|
|
|
assert.Equal(t, uint8(0), level)
|
2022-08-28 00:16:41 +08:00
|
|
|
assert.EqualError(t, err, "sheet SheetN does not exist")
|
2019-12-24 01:09:28 +08:00
|
|
|
|
This closes #1425, breaking changes for sheet name (#1426)
- Checking and return error for invalid sheet name instead of trim invalid characters
- Add error return for the 4 functions: `DeleteSheet`, `GetSheetIndex`, `GetSheetVisible` and `SetSheetName`
- Export new error 4 constants: `ErrSheetNameBlank`, `ErrSheetNameInvalid`, `ErrSheetNameLength` and `ErrSheetNameSingleQuote`
- Rename exported error constant `ErrExistsWorksheet` to `ErrExistsSheet`
- Update unit tests for 90 functions: `AddChart`, `AddChartSheet`, `AddComment`, `AddDataValidation`, `AddPicture`, `AddPictureFromBytes`, `AddPivotTable`, `AddShape`, `AddSparkline`, `AddTable`, `AutoFilter`, `CalcCellValue`, `Cols`, `DeleteChart`, `DeleteComment`, `DeleteDataValidation`, `DeletePicture`, `DeleteSheet`, `DuplicateRow`, `DuplicateRowTo`, `GetCellFormula`, `GetCellHyperLink`, `GetCellRichText`, `GetCellStyle`, `GetCellType`, `GetCellValue`, `GetColOutlineLevel`, `GetCols`, `GetColStyle`, `GetColVisible`, `GetColWidth`, `GetConditionalFormats`, `GetDataValidations`, `GetMergeCells`, `GetPageLayout`, `GetPageMargins`, `GetPicture`, `GetRowHeight`, `GetRowOutlineLevel`, `GetRows`, `GetRowVisible`, `GetSheetIndex`, `GetSheetProps`, `GetSheetVisible`, `GroupSheets`, `InsertCol`, `InsertPageBreak`, `InsertRows`, `MergeCell`, `NewSheet`, `NewStreamWriter`, `ProtectSheet`, `RemoveCol`, `RemovePageBreak`, `RemoveRow`, `Rows`, `SearchSheet`, `SetCellBool`, `SetCellDefault`, `SetCellFloat`, `SetCellFormula`, `SetCellHyperLink`, `SetCellInt`, `SetCellRichText`, `SetCellStr`, `SetCellStyle`, `SetCellValue`, `SetColOutlineLevel`, `SetColStyle`, `SetColVisible`, `SetColWidth`, `SetConditionalFormat`, `SetHeaderFooter`, `SetPageLayout`, `SetPageMargins`, `SetPanes`, `SetRowHeight`, `SetRowOutlineLevel`, `SetRowStyle`, `SetRowVisible`, `SetSheetBackground`, `SetSheetBackgroundFromBytes`, `SetSheetCol`, `SetSheetName`, `SetSheetProps`, `SetSheetRow`, `SetSheetVisible`, `UnmergeCell`, `UnprotectSheet` and
`UnsetConditionalFormat`
- Update documentation of the set style functions
Co-authored-by: guoweikuang <weikuang.guo@shopee.com>
2022-12-23 00:54:40 +08:00
|
|
|
// Test column outline level with invalid sheet name
|
|
|
|
_, err = f.GetColOutlineLevel("Sheet:1", "A")
|
|
|
|
assert.EqualError(t, err, ErrSheetNameInvalid.Error())
|
|
|
|
|
2019-09-24 21:53:19 +08:00
|
|
|
assert.NoError(t, f.SetColWidth("Sheet2", "A", "D", 13))
|
2021-05-10 00:09:24 +08:00
|
|
|
assert.EqualError(t, f.SetColWidth("Sheet2", "A", "D", MaxColumnWidth+1), ErrColumnWidth.Error())
|
This closes #1425, breaking changes for sheet name (#1426)
- Checking and return error for invalid sheet name instead of trim invalid characters
- Add error return for the 4 functions: `DeleteSheet`, `GetSheetIndex`, `GetSheetVisible` and `SetSheetName`
- Export new error 4 constants: `ErrSheetNameBlank`, `ErrSheetNameInvalid`, `ErrSheetNameLength` and `ErrSheetNameSingleQuote`
- Rename exported error constant `ErrExistsWorksheet` to `ErrExistsSheet`
- Update unit tests for 90 functions: `AddChart`, `AddChartSheet`, `AddComment`, `AddDataValidation`, `AddPicture`, `AddPictureFromBytes`, `AddPivotTable`, `AddShape`, `AddSparkline`, `AddTable`, `AutoFilter`, `CalcCellValue`, `Cols`, `DeleteChart`, `DeleteComment`, `DeleteDataValidation`, `DeletePicture`, `DeleteSheet`, `DuplicateRow`, `DuplicateRowTo`, `GetCellFormula`, `GetCellHyperLink`, `GetCellRichText`, `GetCellStyle`, `GetCellType`, `GetCellValue`, `GetColOutlineLevel`, `GetCols`, `GetColStyle`, `GetColVisible`, `GetColWidth`, `GetConditionalFormats`, `GetDataValidations`, `GetMergeCells`, `GetPageLayout`, `GetPageMargins`, `GetPicture`, `GetRowHeight`, `GetRowOutlineLevel`, `GetRows`, `GetRowVisible`, `GetSheetIndex`, `GetSheetProps`, `GetSheetVisible`, `GroupSheets`, `InsertCol`, `InsertPageBreak`, `InsertRows`, `MergeCell`, `NewSheet`, `NewStreamWriter`, `ProtectSheet`, `RemoveCol`, `RemovePageBreak`, `RemoveRow`, `Rows`, `SearchSheet`, `SetCellBool`, `SetCellDefault`, `SetCellFloat`, `SetCellFormula`, `SetCellHyperLink`, `SetCellInt`, `SetCellRichText`, `SetCellStr`, `SetCellStyle`, `SetCellValue`, `SetColOutlineLevel`, `SetColStyle`, `SetColVisible`, `SetColWidth`, `SetConditionalFormat`, `SetHeaderFooter`, `SetPageLayout`, `SetPageMargins`, `SetPanes`, `SetRowHeight`, `SetRowOutlineLevel`, `SetRowStyle`, `SetRowVisible`, `SetSheetBackground`, `SetSheetBackgroundFromBytes`, `SetSheetCol`, `SetSheetName`, `SetSheetProps`, `SetSheetRow`, `SetSheetVisible`, `UnmergeCell`, `UnprotectSheet` and
`UnsetConditionalFormat`
- Update documentation of the set style functions
Co-authored-by: guoweikuang <weikuang.guo@shopee.com>
2022-12-23 00:54:40 +08:00
|
|
|
// Test set column width with invalid sheet name
|
|
|
|
assert.EqualError(t, f.SetColWidth("Sheet:1", "A", "D", 13), ErrSheetNameInvalid.Error())
|
2020-09-18 22:20:58 +08:00
|
|
|
|
2019-09-24 21:53:19 +08:00
|
|
|
assert.NoError(t, f.SetColOutlineLevel("Sheet2", "B", 2))
|
|
|
|
assert.NoError(t, f.SetRowOutlineLevel("Sheet1", 2, 7))
|
2021-05-10 00:09:24 +08:00
|
|
|
assert.EqualError(t, f.SetColOutlineLevel("Sheet1", "D", 8), ErrOutlineLevel.Error())
|
|
|
|
assert.EqualError(t, f.SetRowOutlineLevel("Sheet1", 2, 8), ErrOutlineLevel.Error())
|
This closes #1425, breaking changes for sheet name (#1426)
- Checking and return error for invalid sheet name instead of trim invalid characters
- Add error return for the 4 functions: `DeleteSheet`, `GetSheetIndex`, `GetSheetVisible` and `SetSheetName`
- Export new error 4 constants: `ErrSheetNameBlank`, `ErrSheetNameInvalid`, `ErrSheetNameLength` and `ErrSheetNameSingleQuote`
- Rename exported error constant `ErrExistsWorksheet` to `ErrExistsSheet`
- Update unit tests for 90 functions: `AddChart`, `AddChartSheet`, `AddComment`, `AddDataValidation`, `AddPicture`, `AddPictureFromBytes`, `AddPivotTable`, `AddShape`, `AddSparkline`, `AddTable`, `AutoFilter`, `CalcCellValue`, `Cols`, `DeleteChart`, `DeleteComment`, `DeleteDataValidation`, `DeletePicture`, `DeleteSheet`, `DuplicateRow`, `DuplicateRowTo`, `GetCellFormula`, `GetCellHyperLink`, `GetCellRichText`, `GetCellStyle`, `GetCellType`, `GetCellValue`, `GetColOutlineLevel`, `GetCols`, `GetColStyle`, `GetColVisible`, `GetColWidth`, `GetConditionalFormats`, `GetDataValidations`, `GetMergeCells`, `GetPageLayout`, `GetPageMargins`, `GetPicture`, `GetRowHeight`, `GetRowOutlineLevel`, `GetRows`, `GetRowVisible`, `GetSheetIndex`, `GetSheetProps`, `GetSheetVisible`, `GroupSheets`, `InsertCol`, `InsertPageBreak`, `InsertRows`, `MergeCell`, `NewSheet`, `NewStreamWriter`, `ProtectSheet`, `RemoveCol`, `RemovePageBreak`, `RemoveRow`, `Rows`, `SearchSheet`, `SetCellBool`, `SetCellDefault`, `SetCellFloat`, `SetCellFormula`, `SetCellHyperLink`, `SetCellInt`, `SetCellRichText`, `SetCellStr`, `SetCellStyle`, `SetCellValue`, `SetColOutlineLevel`, `SetColStyle`, `SetColVisible`, `SetColWidth`, `SetConditionalFormat`, `SetHeaderFooter`, `SetPageLayout`, `SetPageMargins`, `SetPanes`, `SetRowHeight`, `SetRowOutlineLevel`, `SetRowStyle`, `SetRowVisible`, `SetSheetBackground`, `SetSheetBackgroundFromBytes`, `SetSheetCol`, `SetSheetName`, `SetSheetProps`, `SetSheetRow`, `SetSheetVisible`, `UnmergeCell`, `UnprotectSheet` and
`UnsetConditionalFormat`
- Update documentation of the set style functions
Co-authored-by: guoweikuang <weikuang.guo@shopee.com>
2022-12-23 00:54:40 +08:00
|
|
|
// Test set row outline level on not exists worksheet
|
2022-08-28 00:16:41 +08:00
|
|
|
assert.EqualError(t, f.SetRowOutlineLevel("SheetN", 1, 4), "sheet SheetN does not exist")
|
This closes #1425, breaking changes for sheet name (#1426)
- Checking and return error for invalid sheet name instead of trim invalid characters
- Add error return for the 4 functions: `DeleteSheet`, `GetSheetIndex`, `GetSheetVisible` and `SetSheetName`
- Export new error 4 constants: `ErrSheetNameBlank`, `ErrSheetNameInvalid`, `ErrSheetNameLength` and `ErrSheetNameSingleQuote`
- Rename exported error constant `ErrExistsWorksheet` to `ErrExistsSheet`
- Update unit tests for 90 functions: `AddChart`, `AddChartSheet`, `AddComment`, `AddDataValidation`, `AddPicture`, `AddPictureFromBytes`, `AddPivotTable`, `AddShape`, `AddSparkline`, `AddTable`, `AutoFilter`, `CalcCellValue`, `Cols`, `DeleteChart`, `DeleteComment`, `DeleteDataValidation`, `DeletePicture`, `DeleteSheet`, `DuplicateRow`, `DuplicateRowTo`, `GetCellFormula`, `GetCellHyperLink`, `GetCellRichText`, `GetCellStyle`, `GetCellType`, `GetCellValue`, `GetColOutlineLevel`, `GetCols`, `GetColStyle`, `GetColVisible`, `GetColWidth`, `GetConditionalFormats`, `GetDataValidations`, `GetMergeCells`, `GetPageLayout`, `GetPageMargins`, `GetPicture`, `GetRowHeight`, `GetRowOutlineLevel`, `GetRows`, `GetRowVisible`, `GetSheetIndex`, `GetSheetProps`, `GetSheetVisible`, `GroupSheets`, `InsertCol`, `InsertPageBreak`, `InsertRows`, `MergeCell`, `NewSheet`, `NewStreamWriter`, `ProtectSheet`, `RemoveCol`, `RemovePageBreak`, `RemoveRow`, `Rows`, `SearchSheet`, `SetCellBool`, `SetCellDefault`, `SetCellFloat`, `SetCellFormula`, `SetCellHyperLink`, `SetCellInt`, `SetCellRichText`, `SetCellStr`, `SetCellStyle`, `SetCellValue`, `SetColOutlineLevel`, `SetColStyle`, `SetColVisible`, `SetColWidth`, `SetConditionalFormat`, `SetHeaderFooter`, `SetPageLayout`, `SetPageMargins`, `SetPanes`, `SetRowHeight`, `SetRowOutlineLevel`, `SetRowStyle`, `SetRowVisible`, `SetSheetBackground`, `SetSheetBackgroundFromBytes`, `SetSheetCol`, `SetSheetName`, `SetSheetProps`, `SetSheetRow`, `SetSheetVisible`, `UnmergeCell`, `UnprotectSheet` and
`UnsetConditionalFormat`
- Update documentation of the set style functions
Co-authored-by: guoweikuang <weikuang.guo@shopee.com>
2022-12-23 00:54:40 +08:00
|
|
|
// Test set row outline level with invalid sheet name
|
|
|
|
assert.EqualError(t, f.SetRowOutlineLevel("Sheet:1", 1, 4), ErrSheetNameInvalid.Error())
|
|
|
|
// Test get row outline level on not exists worksheet
|
2019-12-24 01:09:28 +08:00
|
|
|
_, err = f.GetRowOutlineLevel("SheetN", 1)
|
2022-08-28 00:16:41 +08:00
|
|
|
assert.EqualError(t, err, "sheet SheetN does not exist")
|
This closes #1425, breaking changes for sheet name (#1426)
- Checking and return error for invalid sheet name instead of trim invalid characters
- Add error return for the 4 functions: `DeleteSheet`, `GetSheetIndex`, `GetSheetVisible` and `SetSheetName`
- Export new error 4 constants: `ErrSheetNameBlank`, `ErrSheetNameInvalid`, `ErrSheetNameLength` and `ErrSheetNameSingleQuote`
- Rename exported error constant `ErrExistsWorksheet` to `ErrExistsSheet`
- Update unit tests for 90 functions: `AddChart`, `AddChartSheet`, `AddComment`, `AddDataValidation`, `AddPicture`, `AddPictureFromBytes`, `AddPivotTable`, `AddShape`, `AddSparkline`, `AddTable`, `AutoFilter`, `CalcCellValue`, `Cols`, `DeleteChart`, `DeleteComment`, `DeleteDataValidation`, `DeletePicture`, `DeleteSheet`, `DuplicateRow`, `DuplicateRowTo`, `GetCellFormula`, `GetCellHyperLink`, `GetCellRichText`, `GetCellStyle`, `GetCellType`, `GetCellValue`, `GetColOutlineLevel`, `GetCols`, `GetColStyle`, `GetColVisible`, `GetColWidth`, `GetConditionalFormats`, `GetDataValidations`, `GetMergeCells`, `GetPageLayout`, `GetPageMargins`, `GetPicture`, `GetRowHeight`, `GetRowOutlineLevel`, `GetRows`, `GetRowVisible`, `GetSheetIndex`, `GetSheetProps`, `GetSheetVisible`, `GroupSheets`, `InsertCol`, `InsertPageBreak`, `InsertRows`, `MergeCell`, `NewSheet`, `NewStreamWriter`, `ProtectSheet`, `RemoveCol`, `RemovePageBreak`, `RemoveRow`, `Rows`, `SearchSheet`, `SetCellBool`, `SetCellDefault`, `SetCellFloat`, `SetCellFormula`, `SetCellHyperLink`, `SetCellInt`, `SetCellRichText`, `SetCellStr`, `SetCellStyle`, `SetCellValue`, `SetColOutlineLevel`, `SetColStyle`, `SetColVisible`, `SetColWidth`, `SetConditionalFormat`, `SetHeaderFooter`, `SetPageLayout`, `SetPageMargins`, `SetPanes`, `SetRowHeight`, `SetRowOutlineLevel`, `SetRowStyle`, `SetRowVisible`, `SetSheetBackground`, `SetSheetBackgroundFromBytes`, `SetSheetCol`, `SetSheetName`, `SetSheetProps`, `SetSheetRow`, `SetSheetVisible`, `UnmergeCell`, `UnprotectSheet` and
`UnsetConditionalFormat`
- Update documentation of the set style functions
Co-authored-by: guoweikuang <weikuang.guo@shopee.com>
2022-12-23 00:54:40 +08:00
|
|
|
// Test get row outline level with invalid sheet name
|
|
|
|
_, err = f.GetRowOutlineLevel("Sheet:1", 1)
|
|
|
|
assert.EqualError(t, err, ErrSheetNameInvalid.Error())
|
|
|
|
// Test set and get column outline level with illegal cell reference
|
2021-12-07 00:26:53 +08:00
|
|
|
assert.EqualError(t, f.SetColOutlineLevel("Sheet1", "*", 1), newInvalidColumnNameError("*").Error())
|
2019-10-26 20:55:24 +08:00
|
|
|
_, err = f.GetColOutlineLevel("Sheet1", "*")
|
2021-12-07 00:26:53 +08:00
|
|
|
assert.EqualError(t, err, newInvalidColumnNameError("*").Error())
|
2019-05-16 13:36:50 +08:00
|
|
|
|
This closes #1425, breaking changes for sheet name (#1426)
- Checking and return error for invalid sheet name instead of trim invalid characters
- Add error return for the 4 functions: `DeleteSheet`, `GetSheetIndex`, `GetSheetVisible` and `SetSheetName`
- Export new error 4 constants: `ErrSheetNameBlank`, `ErrSheetNameInvalid`, `ErrSheetNameLength` and `ErrSheetNameSingleQuote`
- Rename exported error constant `ErrExistsWorksheet` to `ErrExistsSheet`
- Update unit tests for 90 functions: `AddChart`, `AddChartSheet`, `AddComment`, `AddDataValidation`, `AddPicture`, `AddPictureFromBytes`, `AddPivotTable`, `AddShape`, `AddSparkline`, `AddTable`, `AutoFilter`, `CalcCellValue`, `Cols`, `DeleteChart`, `DeleteComment`, `DeleteDataValidation`, `DeletePicture`, `DeleteSheet`, `DuplicateRow`, `DuplicateRowTo`, `GetCellFormula`, `GetCellHyperLink`, `GetCellRichText`, `GetCellStyle`, `GetCellType`, `GetCellValue`, `GetColOutlineLevel`, `GetCols`, `GetColStyle`, `GetColVisible`, `GetColWidth`, `GetConditionalFormats`, `GetDataValidations`, `GetMergeCells`, `GetPageLayout`, `GetPageMargins`, `GetPicture`, `GetRowHeight`, `GetRowOutlineLevel`, `GetRows`, `GetRowVisible`, `GetSheetIndex`, `GetSheetProps`, `GetSheetVisible`, `GroupSheets`, `InsertCol`, `InsertPageBreak`, `InsertRows`, `MergeCell`, `NewSheet`, `NewStreamWriter`, `ProtectSheet`, `RemoveCol`, `RemovePageBreak`, `RemoveRow`, `Rows`, `SearchSheet`, `SetCellBool`, `SetCellDefault`, `SetCellFloat`, `SetCellFormula`, `SetCellHyperLink`, `SetCellInt`, `SetCellRichText`, `SetCellStr`, `SetCellStyle`, `SetCellValue`, `SetColOutlineLevel`, `SetColStyle`, `SetColVisible`, `SetColWidth`, `SetConditionalFormat`, `SetHeaderFooter`, `SetPageLayout`, `SetPageMargins`, `SetPanes`, `SetRowHeight`, `SetRowOutlineLevel`, `SetRowStyle`, `SetRowVisible`, `SetSheetBackground`, `SetSheetBackgroundFromBytes`, `SetSheetCol`, `SetSheetName`, `SetSheetProps`, `SetSheetRow`, `SetSheetVisible`, `UnmergeCell`, `UnprotectSheet` and
`UnsetConditionalFormat`
- Update documentation of the set style functions
Co-authored-by: guoweikuang <weikuang.guo@shopee.com>
2022-12-23 00:54:40 +08:00
|
|
|
// Test set column outline level on not exists worksheet
|
2022-08-28 00:16:41 +08:00
|
|
|
assert.EqualError(t, f.SetColOutlineLevel("SheetN", "E", 2), "sheet SheetN does not exist")
|
2019-05-16 13:36:50 +08:00
|
|
|
|
2021-12-07 00:26:53 +08:00
|
|
|
assert.EqualError(t, f.SetRowOutlineLevel("Sheet1", 0, 1), newInvalidRowNumberError(0).Error())
|
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)
|
2021-12-07 00:26:53 +08:00
|
|
|
assert.EqualError(t, err, newInvalidRowNumberError(0).Error())
|
2019-05-16 13:36:50 +08:00
|
|
|
|
|
|
|
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))
|
2021-09-18 23:20:24 +08:00
|
|
|
assert.NoError(t, f.Close())
|
2019-05-16 13:36:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSetColStyle(t *testing.T) {
|
|
|
|
f := NewFile()
|
2021-07-08 00:52:07 +08:00
|
|
|
assert.NoError(t, f.SetCellValue("Sheet1", "B2", "Hello"))
|
Breaking change: changed the function signature for 11 exported functions
* Change
`func (f *File) NewConditionalStyle(style string) (int, error)`
to
`func (f *File) NewConditionalStyle(style *Style) (int, error)`
* Change
`func (f *File) NewStyle(style interface{}) (int, error)`
to
`func (f *File) NewStyle(style *Style) (int, error)`
* Change
`func (f *File) AddChart(sheet, cell, opts string, combo ...string) error`
to
`func (f *File) AddChart(sheet, cell string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddChartSheet(sheet, opts string, combo ...string) error`
to
`func (f *File) AddChartSheet(sheet string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddShape(sheet, cell, opts string) error`
to
`func (f *File) AddShape(sheet, cell string, opts *Shape) error`
* Change
`func (f *File) AddPictureFromBytes(sheet, cell, opts, name, extension string, file []byte) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *PictureOptions) error`
* Change
`func (f *File) AddTable(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AddTable(sheet, reference string, opts *TableOptions) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) AutoFilter(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AutoFilter(sheet, reference string, opts *AutoFilterOptions) error`
* Change
`func (f *File) SetPanes(sheet, panes string) error`
to
`func (f *File) SetPanes(sheet string, panes *Panes) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) SetConditionalFormat(sheet, reference, opts string) error`
to
`func (f *File) SetConditionalFormat(sheet, reference string, opts []ConditionalFormatOptions) error`
* Add exported types:
* AutoFilterListOptions
* AutoFilterOptions
* Chart
* ChartAxis
* ChartDimension
* ChartLegend
* ChartLine
* ChartMarker
* ChartPlotArea
* ChartSeries
* ChartTitle
* ConditionalFormatOptions
* PaneOptions
* Panes
* PictureOptions
* Shape
* ShapeColor
* ShapeLine
* ShapeParagraph
* TableOptions
* This added support for set sheet visible as very hidden
* Return error when missing required parameters for set defined name
* Update unit test and comments
2022-12-30 00:50:08 +08:00
|
|
|
|
|
|
|
styleID, err := f.NewStyle(&Style{Fill: Fill{Type: "pattern", Color: []string{"#94d3a2"}, Pattern: 1}})
|
2019-05-16 13:36:50 +08:00
|
|
|
assert.NoError(t, err)
|
This closes #1425, breaking changes for sheet name (#1426)
- Checking and return error for invalid sheet name instead of trim invalid characters
- Add error return for the 4 functions: `DeleteSheet`, `GetSheetIndex`, `GetSheetVisible` and `SetSheetName`
- Export new error 4 constants: `ErrSheetNameBlank`, `ErrSheetNameInvalid`, `ErrSheetNameLength` and `ErrSheetNameSingleQuote`
- Rename exported error constant `ErrExistsWorksheet` to `ErrExistsSheet`
- Update unit tests for 90 functions: `AddChart`, `AddChartSheet`, `AddComment`, `AddDataValidation`, `AddPicture`, `AddPictureFromBytes`, `AddPivotTable`, `AddShape`, `AddSparkline`, `AddTable`, `AutoFilter`, `CalcCellValue`, `Cols`, `DeleteChart`, `DeleteComment`, `DeleteDataValidation`, `DeletePicture`, `DeleteSheet`, `DuplicateRow`, `DuplicateRowTo`, `GetCellFormula`, `GetCellHyperLink`, `GetCellRichText`, `GetCellStyle`, `GetCellType`, `GetCellValue`, `GetColOutlineLevel`, `GetCols`, `GetColStyle`, `GetColVisible`, `GetColWidth`, `GetConditionalFormats`, `GetDataValidations`, `GetMergeCells`, `GetPageLayout`, `GetPageMargins`, `GetPicture`, `GetRowHeight`, `GetRowOutlineLevel`, `GetRows`, `GetRowVisible`, `GetSheetIndex`, `GetSheetProps`, `GetSheetVisible`, `GroupSheets`, `InsertCol`, `InsertPageBreak`, `InsertRows`, `MergeCell`, `NewSheet`, `NewStreamWriter`, `ProtectSheet`, `RemoveCol`, `RemovePageBreak`, `RemoveRow`, `Rows`, `SearchSheet`, `SetCellBool`, `SetCellDefault`, `SetCellFloat`, `SetCellFormula`, `SetCellHyperLink`, `SetCellInt`, `SetCellRichText`, `SetCellStr`, `SetCellStyle`, `SetCellValue`, `SetColOutlineLevel`, `SetColStyle`, `SetColVisible`, `SetColWidth`, `SetConditionalFormat`, `SetHeaderFooter`, `SetPageLayout`, `SetPageMargins`, `SetPanes`, `SetRowHeight`, `SetRowOutlineLevel`, `SetRowStyle`, `SetRowVisible`, `SetSheetBackground`, `SetSheetBackgroundFromBytes`, `SetSheetCol`, `SetSheetName`, `SetSheetProps`, `SetSheetRow`, `SetSheetVisible`, `UnmergeCell`, `UnprotectSheet` and
`UnsetConditionalFormat`
- Update documentation of the set style functions
Co-authored-by: guoweikuang <weikuang.guo@shopee.com>
2022-12-23 00:54:40 +08:00
|
|
|
// Test set column style on not exists worksheet
|
2022-08-28 00:16:41 +08:00
|
|
|
assert.EqualError(t, f.SetColStyle("SheetN", "E", styleID), "sheet SheetN does not exist")
|
This closes #1425, breaking changes for sheet name (#1426)
- Checking and return error for invalid sheet name instead of trim invalid characters
- Add error return for the 4 functions: `DeleteSheet`, `GetSheetIndex`, `GetSheetVisible` and `SetSheetName`
- Export new error 4 constants: `ErrSheetNameBlank`, `ErrSheetNameInvalid`, `ErrSheetNameLength` and `ErrSheetNameSingleQuote`
- Rename exported error constant `ErrExistsWorksheet` to `ErrExistsSheet`
- Update unit tests for 90 functions: `AddChart`, `AddChartSheet`, `AddComment`, `AddDataValidation`, `AddPicture`, `AddPictureFromBytes`, `AddPivotTable`, `AddShape`, `AddSparkline`, `AddTable`, `AutoFilter`, `CalcCellValue`, `Cols`, `DeleteChart`, `DeleteComment`, `DeleteDataValidation`, `DeletePicture`, `DeleteSheet`, `DuplicateRow`, `DuplicateRowTo`, `GetCellFormula`, `GetCellHyperLink`, `GetCellRichText`, `GetCellStyle`, `GetCellType`, `GetCellValue`, `GetColOutlineLevel`, `GetCols`, `GetColStyle`, `GetColVisible`, `GetColWidth`, `GetConditionalFormats`, `GetDataValidations`, `GetMergeCells`, `GetPageLayout`, `GetPageMargins`, `GetPicture`, `GetRowHeight`, `GetRowOutlineLevel`, `GetRows`, `GetRowVisible`, `GetSheetIndex`, `GetSheetProps`, `GetSheetVisible`, `GroupSheets`, `InsertCol`, `InsertPageBreak`, `InsertRows`, `MergeCell`, `NewSheet`, `NewStreamWriter`, `ProtectSheet`, `RemoveCol`, `RemovePageBreak`, `RemoveRow`, `Rows`, `SearchSheet`, `SetCellBool`, `SetCellDefault`, `SetCellFloat`, `SetCellFormula`, `SetCellHyperLink`, `SetCellInt`, `SetCellRichText`, `SetCellStr`, `SetCellStyle`, `SetCellValue`, `SetColOutlineLevel`, `SetColStyle`, `SetColVisible`, `SetColWidth`, `SetConditionalFormat`, `SetHeaderFooter`, `SetPageLayout`, `SetPageMargins`, `SetPanes`, `SetRowHeight`, `SetRowOutlineLevel`, `SetRowStyle`, `SetRowVisible`, `SetSheetBackground`, `SetSheetBackgroundFromBytes`, `SetSheetCol`, `SetSheetName`, `SetSheetProps`, `SetSheetRow`, `SetSheetVisible`, `UnmergeCell`, `UnprotectSheet` and
`UnsetConditionalFormat`
- Update documentation of the set style functions
Co-authored-by: guoweikuang <weikuang.guo@shopee.com>
2022-12-23 00:54:40 +08:00
|
|
|
// Test set column style with illegal column name
|
2022-01-27 22:37:32 +08:00
|
|
|
assert.EqualError(t, f.SetColStyle("Sheet1", "*", styleID), newInvalidColumnNameError("*").Error())
|
|
|
|
assert.EqualError(t, f.SetColStyle("Sheet1", "A:*", styleID), newInvalidColumnNameError("*").Error())
|
This closes #1425, breaking changes for sheet name (#1426)
- Checking and return error for invalid sheet name instead of trim invalid characters
- Add error return for the 4 functions: `DeleteSheet`, `GetSheetIndex`, `GetSheetVisible` and `SetSheetName`
- Export new error 4 constants: `ErrSheetNameBlank`, `ErrSheetNameInvalid`, `ErrSheetNameLength` and `ErrSheetNameSingleQuote`
- Rename exported error constant `ErrExistsWorksheet` to `ErrExistsSheet`
- Update unit tests for 90 functions: `AddChart`, `AddChartSheet`, `AddComment`, `AddDataValidation`, `AddPicture`, `AddPictureFromBytes`, `AddPivotTable`, `AddShape`, `AddSparkline`, `AddTable`, `AutoFilter`, `CalcCellValue`, `Cols`, `DeleteChart`, `DeleteComment`, `DeleteDataValidation`, `DeletePicture`, `DeleteSheet`, `DuplicateRow`, `DuplicateRowTo`, `GetCellFormula`, `GetCellHyperLink`, `GetCellRichText`, `GetCellStyle`, `GetCellType`, `GetCellValue`, `GetColOutlineLevel`, `GetCols`, `GetColStyle`, `GetColVisible`, `GetColWidth`, `GetConditionalFormats`, `GetDataValidations`, `GetMergeCells`, `GetPageLayout`, `GetPageMargins`, `GetPicture`, `GetRowHeight`, `GetRowOutlineLevel`, `GetRows`, `GetRowVisible`, `GetSheetIndex`, `GetSheetProps`, `GetSheetVisible`, `GroupSheets`, `InsertCol`, `InsertPageBreak`, `InsertRows`, `MergeCell`, `NewSheet`, `NewStreamWriter`, `ProtectSheet`, `RemoveCol`, `RemovePageBreak`, `RemoveRow`, `Rows`, `SearchSheet`, `SetCellBool`, `SetCellDefault`, `SetCellFloat`, `SetCellFormula`, `SetCellHyperLink`, `SetCellInt`, `SetCellRichText`, `SetCellStr`, `SetCellStyle`, `SetCellValue`, `SetColOutlineLevel`, `SetColStyle`, `SetColVisible`, `SetColWidth`, `SetConditionalFormat`, `SetHeaderFooter`, `SetPageLayout`, `SetPageMargins`, `SetPanes`, `SetRowHeight`, `SetRowOutlineLevel`, `SetRowStyle`, `SetRowVisible`, `SetSheetBackground`, `SetSheetBackgroundFromBytes`, `SetSheetCol`, `SetSheetName`, `SetSheetProps`, `SetSheetRow`, `SetSheetVisible`, `UnmergeCell`, `UnprotectSheet` and
`UnsetConditionalFormat`
- Update documentation of the set style functions
Co-authored-by: guoweikuang <weikuang.guo@shopee.com>
2022-12-23 00:54:40 +08:00
|
|
|
// Test set column style with invalid style ID
|
2022-09-01 00:41:52 +08:00
|
|
|
assert.EqualError(t, f.SetColStyle("Sheet1", "B", -1), newInvalidStyleID(-1).Error())
|
This closes #1425, breaking changes for sheet name (#1426)
- Checking and return error for invalid sheet name instead of trim invalid characters
- Add error return for the 4 functions: `DeleteSheet`, `GetSheetIndex`, `GetSheetVisible` and `SetSheetName`
- Export new error 4 constants: `ErrSheetNameBlank`, `ErrSheetNameInvalid`, `ErrSheetNameLength` and `ErrSheetNameSingleQuote`
- Rename exported error constant `ErrExistsWorksheet` to `ErrExistsSheet`
- Update unit tests for 90 functions: `AddChart`, `AddChartSheet`, `AddComment`, `AddDataValidation`, `AddPicture`, `AddPictureFromBytes`, `AddPivotTable`, `AddShape`, `AddSparkline`, `AddTable`, `AutoFilter`, `CalcCellValue`, `Cols`, `DeleteChart`, `DeleteComment`, `DeleteDataValidation`, `DeletePicture`, `DeleteSheet`, `DuplicateRow`, `DuplicateRowTo`, `GetCellFormula`, `GetCellHyperLink`, `GetCellRichText`, `GetCellStyle`, `GetCellType`, `GetCellValue`, `GetColOutlineLevel`, `GetCols`, `GetColStyle`, `GetColVisible`, `GetColWidth`, `GetConditionalFormats`, `GetDataValidations`, `GetMergeCells`, `GetPageLayout`, `GetPageMargins`, `GetPicture`, `GetRowHeight`, `GetRowOutlineLevel`, `GetRows`, `GetRowVisible`, `GetSheetIndex`, `GetSheetProps`, `GetSheetVisible`, `GroupSheets`, `InsertCol`, `InsertPageBreak`, `InsertRows`, `MergeCell`, `NewSheet`, `NewStreamWriter`, `ProtectSheet`, `RemoveCol`, `RemovePageBreak`, `RemoveRow`, `Rows`, `SearchSheet`, `SetCellBool`, `SetCellDefault`, `SetCellFloat`, `SetCellFormula`, `SetCellHyperLink`, `SetCellInt`, `SetCellRichText`, `SetCellStr`, `SetCellStyle`, `SetCellValue`, `SetColOutlineLevel`, `SetColStyle`, `SetColVisible`, `SetColWidth`, `SetConditionalFormat`, `SetHeaderFooter`, `SetPageLayout`, `SetPageMargins`, `SetPanes`, `SetRowHeight`, `SetRowOutlineLevel`, `SetRowStyle`, `SetRowVisible`, `SetSheetBackground`, `SetSheetBackgroundFromBytes`, `SetSheetCol`, `SetSheetName`, `SetSheetProps`, `SetSheetRow`, `SetSheetVisible`, `UnmergeCell`, `UnprotectSheet` and
`UnsetConditionalFormat`
- Update documentation of the set style functions
Co-authored-by: guoweikuang <weikuang.guo@shopee.com>
2022-12-23 00:54:40 +08:00
|
|
|
// Test set column style with not exists style ID
|
2022-09-01 00:41:52 +08:00
|
|
|
assert.EqualError(t, f.SetColStyle("Sheet1", "B", 10), newInvalidStyleID(10).Error())
|
This closes #1425, breaking changes for sheet name (#1426)
- Checking and return error for invalid sheet name instead of trim invalid characters
- Add error return for the 4 functions: `DeleteSheet`, `GetSheetIndex`, `GetSheetVisible` and `SetSheetName`
- Export new error 4 constants: `ErrSheetNameBlank`, `ErrSheetNameInvalid`, `ErrSheetNameLength` and `ErrSheetNameSingleQuote`
- Rename exported error constant `ErrExistsWorksheet` to `ErrExistsSheet`
- Update unit tests for 90 functions: `AddChart`, `AddChartSheet`, `AddComment`, `AddDataValidation`, `AddPicture`, `AddPictureFromBytes`, `AddPivotTable`, `AddShape`, `AddSparkline`, `AddTable`, `AutoFilter`, `CalcCellValue`, `Cols`, `DeleteChart`, `DeleteComment`, `DeleteDataValidation`, `DeletePicture`, `DeleteSheet`, `DuplicateRow`, `DuplicateRowTo`, `GetCellFormula`, `GetCellHyperLink`, `GetCellRichText`, `GetCellStyle`, `GetCellType`, `GetCellValue`, `GetColOutlineLevel`, `GetCols`, `GetColStyle`, `GetColVisible`, `GetColWidth`, `GetConditionalFormats`, `GetDataValidations`, `GetMergeCells`, `GetPageLayout`, `GetPageMargins`, `GetPicture`, `GetRowHeight`, `GetRowOutlineLevel`, `GetRows`, `GetRowVisible`, `GetSheetIndex`, `GetSheetProps`, `GetSheetVisible`, `GroupSheets`, `InsertCol`, `InsertPageBreak`, `InsertRows`, `MergeCell`, `NewSheet`, `NewStreamWriter`, `ProtectSheet`, `RemoveCol`, `RemovePageBreak`, `RemoveRow`, `Rows`, `SearchSheet`, `SetCellBool`, `SetCellDefault`, `SetCellFloat`, `SetCellFormula`, `SetCellHyperLink`, `SetCellInt`, `SetCellRichText`, `SetCellStr`, `SetCellStyle`, `SetCellValue`, `SetColOutlineLevel`, `SetColStyle`, `SetColVisible`, `SetColWidth`, `SetConditionalFormat`, `SetHeaderFooter`, `SetPageLayout`, `SetPageMargins`, `SetPanes`, `SetRowHeight`, `SetRowOutlineLevel`, `SetRowStyle`, `SetRowVisible`, `SetSheetBackground`, `SetSheetBackgroundFromBytes`, `SetSheetCol`, `SetSheetName`, `SetSheetProps`, `SetSheetRow`, `SetSheetVisible`, `UnmergeCell`, `UnprotectSheet` and
`UnsetConditionalFormat`
- Update documentation of the set style functions
Co-authored-by: guoweikuang <weikuang.guo@shopee.com>
2022-12-23 00:54:40 +08:00
|
|
|
// Test set column style with invalid sheet name
|
|
|
|
assert.EqualError(t, f.SetColStyle("Sheet:1", "A", 0), ErrSheetNameInvalid.Error())
|
2019-05-16 13:36:50 +08:00
|
|
|
|
2022-01-27 22:37:32 +08:00
|
|
|
assert.NoError(t, f.SetColStyle("Sheet1", "B", styleID))
|
2022-09-07 00:18:16 +08:00
|
|
|
style, err := f.GetColStyle("Sheet1", "B")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, styleID, style)
|
|
|
|
|
This closes #1425, breaking changes for sheet name (#1426)
- Checking and return error for invalid sheet name instead of trim invalid characters
- Add error return for the 4 functions: `DeleteSheet`, `GetSheetIndex`, `GetSheetVisible` and `SetSheetName`
- Export new error 4 constants: `ErrSheetNameBlank`, `ErrSheetNameInvalid`, `ErrSheetNameLength` and `ErrSheetNameSingleQuote`
- Rename exported error constant `ErrExistsWorksheet` to `ErrExistsSheet`
- Update unit tests for 90 functions: `AddChart`, `AddChartSheet`, `AddComment`, `AddDataValidation`, `AddPicture`, `AddPictureFromBytes`, `AddPivotTable`, `AddShape`, `AddSparkline`, `AddTable`, `AutoFilter`, `CalcCellValue`, `Cols`, `DeleteChart`, `DeleteComment`, `DeleteDataValidation`, `DeletePicture`, `DeleteSheet`, `DuplicateRow`, `DuplicateRowTo`, `GetCellFormula`, `GetCellHyperLink`, `GetCellRichText`, `GetCellStyle`, `GetCellType`, `GetCellValue`, `GetColOutlineLevel`, `GetCols`, `GetColStyle`, `GetColVisible`, `GetColWidth`, `GetConditionalFormats`, `GetDataValidations`, `GetMergeCells`, `GetPageLayout`, `GetPageMargins`, `GetPicture`, `GetRowHeight`, `GetRowOutlineLevel`, `GetRows`, `GetRowVisible`, `GetSheetIndex`, `GetSheetProps`, `GetSheetVisible`, `GroupSheets`, `InsertCol`, `InsertPageBreak`, `InsertRows`, `MergeCell`, `NewSheet`, `NewStreamWriter`, `ProtectSheet`, `RemoveCol`, `RemovePageBreak`, `RemoveRow`, `Rows`, `SearchSheet`, `SetCellBool`, `SetCellDefault`, `SetCellFloat`, `SetCellFormula`, `SetCellHyperLink`, `SetCellInt`, `SetCellRichText`, `SetCellStr`, `SetCellStyle`, `SetCellValue`, `SetColOutlineLevel`, `SetColStyle`, `SetColVisible`, `SetColWidth`, `SetConditionalFormat`, `SetHeaderFooter`, `SetPageLayout`, `SetPageMargins`, `SetPanes`, `SetRowHeight`, `SetRowOutlineLevel`, `SetRowStyle`, `SetRowVisible`, `SetSheetBackground`, `SetSheetBackgroundFromBytes`, `SetSheetCol`, `SetSheetName`, `SetSheetProps`, `SetSheetRow`, `SetSheetVisible`, `UnmergeCell`, `UnprotectSheet` and
`UnsetConditionalFormat`
- Update documentation of the set style functions
Co-authored-by: guoweikuang <weikuang.guo@shopee.com>
2022-12-23 00:54:40 +08:00
|
|
|
// Test set column style with already exists column with style
|
2022-01-27 22:37:32 +08:00
|
|
|
assert.NoError(t, f.SetColStyle("Sheet1", "B", styleID))
|
|
|
|
assert.NoError(t, f.SetColStyle("Sheet1", "D:C", styleID))
|
|
|
|
ws, ok := f.Sheet.Load("xl/worksheets/sheet1.xml")
|
|
|
|
assert.True(t, ok)
|
|
|
|
ws.(*xlsxWorksheet).SheetData.Row[1].C[2].S = 0
|
|
|
|
cellStyleID, err := f.GetCellStyle("Sheet1", "C2")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, styleID, cellStyleID)
|
2019-05-16 13:36:50 +08:00
|
|
|
assert.NoError(t, f.SaveAs(filepath.Join("test", "TestSetColStyle.xlsx")))
|
This closes #1425, breaking changes for sheet name (#1426)
- Checking and return error for invalid sheet name instead of trim invalid characters
- Add error return for the 4 functions: `DeleteSheet`, `GetSheetIndex`, `GetSheetVisible` and `SetSheetName`
- Export new error 4 constants: `ErrSheetNameBlank`, `ErrSheetNameInvalid`, `ErrSheetNameLength` and `ErrSheetNameSingleQuote`
- Rename exported error constant `ErrExistsWorksheet` to `ErrExistsSheet`
- Update unit tests for 90 functions: `AddChart`, `AddChartSheet`, `AddComment`, `AddDataValidation`, `AddPicture`, `AddPictureFromBytes`, `AddPivotTable`, `AddShape`, `AddSparkline`, `AddTable`, `AutoFilter`, `CalcCellValue`, `Cols`, `DeleteChart`, `DeleteComment`, `DeleteDataValidation`, `DeletePicture`, `DeleteSheet`, `DuplicateRow`, `DuplicateRowTo`, `GetCellFormula`, `GetCellHyperLink`, `GetCellRichText`, `GetCellStyle`, `GetCellType`, `GetCellValue`, `GetColOutlineLevel`, `GetCols`, `GetColStyle`, `GetColVisible`, `GetColWidth`, `GetConditionalFormats`, `GetDataValidations`, `GetMergeCells`, `GetPageLayout`, `GetPageMargins`, `GetPicture`, `GetRowHeight`, `GetRowOutlineLevel`, `GetRows`, `GetRowVisible`, `GetSheetIndex`, `GetSheetProps`, `GetSheetVisible`, `GroupSheets`, `InsertCol`, `InsertPageBreak`, `InsertRows`, `MergeCell`, `NewSheet`, `NewStreamWriter`, `ProtectSheet`, `RemoveCol`, `RemovePageBreak`, `RemoveRow`, `Rows`, `SearchSheet`, `SetCellBool`, `SetCellDefault`, `SetCellFloat`, `SetCellFormula`, `SetCellHyperLink`, `SetCellInt`, `SetCellRichText`, `SetCellStr`, `SetCellStyle`, `SetCellValue`, `SetColOutlineLevel`, `SetColStyle`, `SetColVisible`, `SetColWidth`, `SetConditionalFormat`, `SetHeaderFooter`, `SetPageLayout`, `SetPageMargins`, `SetPanes`, `SetRowHeight`, `SetRowOutlineLevel`, `SetRowStyle`, `SetRowVisible`, `SetSheetBackground`, `SetSheetBackgroundFromBytes`, `SetSheetCol`, `SetSheetName`, `SetSheetProps`, `SetSheetRow`, `SetSheetVisible`, `UnmergeCell`, `UnprotectSheet` and
`UnsetConditionalFormat`
- Update documentation of the set style functions
Co-authored-by: guoweikuang <weikuang.guo@shopee.com>
2022-12-23 00:54:40 +08:00
|
|
|
// Test set column style with unsupported charset style sheet
|
2022-11-12 00:02:11 +08:00
|
|
|
f.Styles = nil
|
|
|
|
f.Pkg.Store(defaultXMLPathStyles, MacintoshCyrillicCharset)
|
|
|
|
assert.EqualError(t, f.SetColStyle("Sheet1", "C:F", styleID), "XML syntax error on line 1: invalid UTF-8")
|
2019-05-16 13:36:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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")
|
2021-03-05 00:40:37 +08:00
|
|
|
assert.Equal(t, defaultColWidth, width)
|
2019-12-24 01:09:28 +08:00
|
|
|
assert.NoError(t, err)
|
2019-05-16 13:36:50 +08:00
|
|
|
|
This closes #1425, breaking changes for sheet name (#1426)
- Checking and return error for invalid sheet name instead of trim invalid characters
- Add error return for the 4 functions: `DeleteSheet`, `GetSheetIndex`, `GetSheetVisible` and `SetSheetName`
- Export new error 4 constants: `ErrSheetNameBlank`, `ErrSheetNameInvalid`, `ErrSheetNameLength` and `ErrSheetNameSingleQuote`
- Rename exported error constant `ErrExistsWorksheet` to `ErrExistsSheet`
- Update unit tests for 90 functions: `AddChart`, `AddChartSheet`, `AddComment`, `AddDataValidation`, `AddPicture`, `AddPictureFromBytes`, `AddPivotTable`, `AddShape`, `AddSparkline`, `AddTable`, `AutoFilter`, `CalcCellValue`, `Cols`, `DeleteChart`, `DeleteComment`, `DeleteDataValidation`, `DeletePicture`, `DeleteSheet`, `DuplicateRow`, `DuplicateRowTo`, `GetCellFormula`, `GetCellHyperLink`, `GetCellRichText`, `GetCellStyle`, `GetCellType`, `GetCellValue`, `GetColOutlineLevel`, `GetCols`, `GetColStyle`, `GetColVisible`, `GetColWidth`, `GetConditionalFormats`, `GetDataValidations`, `GetMergeCells`, `GetPageLayout`, `GetPageMargins`, `GetPicture`, `GetRowHeight`, `GetRowOutlineLevel`, `GetRows`, `GetRowVisible`, `GetSheetIndex`, `GetSheetProps`, `GetSheetVisible`, `GroupSheets`, `InsertCol`, `InsertPageBreak`, `InsertRows`, `MergeCell`, `NewSheet`, `NewStreamWriter`, `ProtectSheet`, `RemoveCol`, `RemovePageBreak`, `RemoveRow`, `Rows`, `SearchSheet`, `SetCellBool`, `SetCellDefault`, `SetCellFloat`, `SetCellFormula`, `SetCellHyperLink`, `SetCellInt`, `SetCellRichText`, `SetCellStr`, `SetCellStyle`, `SetCellValue`, `SetColOutlineLevel`, `SetColStyle`, `SetColVisible`, `SetColWidth`, `SetConditionalFormat`, `SetHeaderFooter`, `SetPageLayout`, `SetPageMargins`, `SetPanes`, `SetRowHeight`, `SetRowOutlineLevel`, `SetRowStyle`, `SetRowVisible`, `SetSheetBackground`, `SetSheetBackgroundFromBytes`, `SetSheetCol`, `SetSheetName`, `SetSheetProps`, `SetSheetRow`, `SetSheetVisible`, `UnmergeCell`, `UnprotectSheet` and
`UnsetConditionalFormat`
- Update documentation of the set style functions
Co-authored-by: guoweikuang <weikuang.guo@shopee.com>
2022-12-23 00:54:40 +08:00
|
|
|
// Test set and get column width with illegal cell reference
|
2019-12-24 01:09:28 +08:00
|
|
|
width, err = f.GetColWidth("Sheet1", "*")
|
2021-03-05 00:40:37 +08:00
|
|
|
assert.Equal(t, defaultColWidth, width)
|
2021-12-07 00:26:53 +08:00
|
|
|
assert.EqualError(t, err, newInvalidColumnNameError("*").Error())
|
|
|
|
assert.EqualError(t, f.SetColWidth("Sheet1", "*", "B", 1), newInvalidColumnNameError("*").Error())
|
|
|
|
assert.EqualError(t, f.SetColWidth("Sheet1", "A", "*", 1), newInvalidColumnNameError("*").Error())
|
2019-05-16 13:36:50 +08:00
|
|
|
|
This closes #1425, breaking changes for sheet name (#1426)
- Checking and return error for invalid sheet name instead of trim invalid characters
- Add error return for the 4 functions: `DeleteSheet`, `GetSheetIndex`, `GetSheetVisible` and `SetSheetName`
- Export new error 4 constants: `ErrSheetNameBlank`, `ErrSheetNameInvalid`, `ErrSheetNameLength` and `ErrSheetNameSingleQuote`
- Rename exported error constant `ErrExistsWorksheet` to `ErrExistsSheet`
- Update unit tests for 90 functions: `AddChart`, `AddChartSheet`, `AddComment`, `AddDataValidation`, `AddPicture`, `AddPictureFromBytes`, `AddPivotTable`, `AddShape`, `AddSparkline`, `AddTable`, `AutoFilter`, `CalcCellValue`, `Cols`, `DeleteChart`, `DeleteComment`, `DeleteDataValidation`, `DeletePicture`, `DeleteSheet`, `DuplicateRow`, `DuplicateRowTo`, `GetCellFormula`, `GetCellHyperLink`, `GetCellRichText`, `GetCellStyle`, `GetCellType`, `GetCellValue`, `GetColOutlineLevel`, `GetCols`, `GetColStyle`, `GetColVisible`, `GetColWidth`, `GetConditionalFormats`, `GetDataValidations`, `GetMergeCells`, `GetPageLayout`, `GetPageMargins`, `GetPicture`, `GetRowHeight`, `GetRowOutlineLevel`, `GetRows`, `GetRowVisible`, `GetSheetIndex`, `GetSheetProps`, `GetSheetVisible`, `GroupSheets`, `InsertCol`, `InsertPageBreak`, `InsertRows`, `MergeCell`, `NewSheet`, `NewStreamWriter`, `ProtectSheet`, `RemoveCol`, `RemovePageBreak`, `RemoveRow`, `Rows`, `SearchSheet`, `SetCellBool`, `SetCellDefault`, `SetCellFloat`, `SetCellFormula`, `SetCellHyperLink`, `SetCellInt`, `SetCellRichText`, `SetCellStr`, `SetCellStyle`, `SetCellValue`, `SetColOutlineLevel`, `SetColStyle`, `SetColVisible`, `SetColWidth`, `SetConditionalFormat`, `SetHeaderFooter`, `SetPageLayout`, `SetPageMargins`, `SetPanes`, `SetRowHeight`, `SetRowOutlineLevel`, `SetRowStyle`, `SetRowVisible`, `SetSheetBackground`, `SetSheetBackgroundFromBytes`, `SetSheetCol`, `SetSheetName`, `SetSheetProps`, `SetSheetRow`, `SetSheetVisible`, `UnmergeCell`, `UnprotectSheet` and
`UnsetConditionalFormat`
- Update documentation of the set style functions
Co-authored-by: guoweikuang <weikuang.guo@shopee.com>
2022-12-23 00:54:40 +08:00
|
|
|
// Test set column width on not exists worksheet
|
2022-08-28 00:16:41 +08:00
|
|
|
assert.EqualError(t, f.SetColWidth("SheetN", "B", "A", 12), "sheet SheetN does not exist")
|
This closes #1425, breaking changes for sheet name (#1426)
- Checking and return error for invalid sheet name instead of trim invalid characters
- Add error return for the 4 functions: `DeleteSheet`, `GetSheetIndex`, `GetSheetVisible` and `SetSheetName`
- Export new error 4 constants: `ErrSheetNameBlank`, `ErrSheetNameInvalid`, `ErrSheetNameLength` and `ErrSheetNameSingleQuote`
- Rename exported error constant `ErrExistsWorksheet` to `ErrExistsSheet`
- Update unit tests for 90 functions: `AddChart`, `AddChartSheet`, `AddComment`, `AddDataValidation`, `AddPicture`, `AddPictureFromBytes`, `AddPivotTable`, `AddShape`, `AddSparkline`, `AddTable`, `AutoFilter`, `CalcCellValue`, `Cols`, `DeleteChart`, `DeleteComment`, `DeleteDataValidation`, `DeletePicture`, `DeleteSheet`, `DuplicateRow`, `DuplicateRowTo`, `GetCellFormula`, `GetCellHyperLink`, `GetCellRichText`, `GetCellStyle`, `GetCellType`, `GetCellValue`, `GetColOutlineLevel`, `GetCols`, `GetColStyle`, `GetColVisible`, `GetColWidth`, `GetConditionalFormats`, `GetDataValidations`, `GetMergeCells`, `GetPageLayout`, `GetPageMargins`, `GetPicture`, `GetRowHeight`, `GetRowOutlineLevel`, `GetRows`, `GetRowVisible`, `GetSheetIndex`, `GetSheetProps`, `GetSheetVisible`, `GroupSheets`, `InsertCol`, `InsertPageBreak`, `InsertRows`, `MergeCell`, `NewSheet`, `NewStreamWriter`, `ProtectSheet`, `RemoveCol`, `RemovePageBreak`, `RemoveRow`, `Rows`, `SearchSheet`, `SetCellBool`, `SetCellDefault`, `SetCellFloat`, `SetCellFormula`, `SetCellHyperLink`, `SetCellInt`, `SetCellRichText`, `SetCellStr`, `SetCellStyle`, `SetCellValue`, `SetColOutlineLevel`, `SetColStyle`, `SetColVisible`, `SetColWidth`, `SetConditionalFormat`, `SetHeaderFooter`, `SetPageLayout`, `SetPageMargins`, `SetPanes`, `SetRowHeight`, `SetRowOutlineLevel`, `SetRowStyle`, `SetRowVisible`, `SetSheetBackground`, `SetSheetBackgroundFromBytes`, `SetSheetCol`, `SetSheetName`, `SetSheetProps`, `SetSheetRow`, `SetSheetVisible`, `UnmergeCell`, `UnprotectSheet` and
`UnsetConditionalFormat`
- Update documentation of the set style functions
Co-authored-by: guoweikuang <weikuang.guo@shopee.com>
2022-12-23 00:54:40 +08:00
|
|
|
// Test get column width on not exists worksheet
|
2019-05-16 13:36:50 +08:00
|
|
|
_, err = f.GetColWidth("SheetN", "A")
|
2022-08-28 00:16:41 +08:00
|
|
|
assert.EqualError(t, err, "sheet SheetN does not exist")
|
This closes #1425, breaking changes for sheet name (#1426)
- Checking and return error for invalid sheet name instead of trim invalid characters
- Add error return for the 4 functions: `DeleteSheet`, `GetSheetIndex`, `GetSheetVisible` and `SetSheetName`
- Export new error 4 constants: `ErrSheetNameBlank`, `ErrSheetNameInvalid`, `ErrSheetNameLength` and `ErrSheetNameSingleQuote`
- Rename exported error constant `ErrExistsWorksheet` to `ErrExistsSheet`
- Update unit tests for 90 functions: `AddChart`, `AddChartSheet`, `AddComment`, `AddDataValidation`, `AddPicture`, `AddPictureFromBytes`, `AddPivotTable`, `AddShape`, `AddSparkline`, `AddTable`, `AutoFilter`, `CalcCellValue`, `Cols`, `DeleteChart`, `DeleteComment`, `DeleteDataValidation`, `DeletePicture`, `DeleteSheet`, `DuplicateRow`, `DuplicateRowTo`, `GetCellFormula`, `GetCellHyperLink`, `GetCellRichText`, `GetCellStyle`, `GetCellType`, `GetCellValue`, `GetColOutlineLevel`, `GetCols`, `GetColStyle`, `GetColVisible`, `GetColWidth`, `GetConditionalFormats`, `GetDataValidations`, `GetMergeCells`, `GetPageLayout`, `GetPageMargins`, `GetPicture`, `GetRowHeight`, `GetRowOutlineLevel`, `GetRows`, `GetRowVisible`, `GetSheetIndex`, `GetSheetProps`, `GetSheetVisible`, `GroupSheets`, `InsertCol`, `InsertPageBreak`, `InsertRows`, `MergeCell`, `NewSheet`, `NewStreamWriter`, `ProtectSheet`, `RemoveCol`, `RemovePageBreak`, `RemoveRow`, `Rows`, `SearchSheet`, `SetCellBool`, `SetCellDefault`, `SetCellFloat`, `SetCellFormula`, `SetCellHyperLink`, `SetCellInt`, `SetCellRichText`, `SetCellStr`, `SetCellStyle`, `SetCellValue`, `SetColOutlineLevel`, `SetColStyle`, `SetColVisible`, `SetColWidth`, `SetConditionalFormat`, `SetHeaderFooter`, `SetPageLayout`, `SetPageMargins`, `SetPanes`, `SetRowHeight`, `SetRowOutlineLevel`, `SetRowStyle`, `SetRowVisible`, `SetSheetBackground`, `SetSheetBackgroundFromBytes`, `SetSheetCol`, `SetSheetName`, `SetSheetProps`, `SetSheetRow`, `SetSheetVisible`, `UnmergeCell`, `UnprotectSheet` and
`UnsetConditionalFormat`
- Update documentation of the set style functions
Co-authored-by: guoweikuang <weikuang.guo@shopee.com>
2022-12-23 00:54:40 +08:00
|
|
|
// Test get column width invalid sheet name
|
|
|
|
_, err = f.GetColWidth("Sheet:1", "A")
|
|
|
|
assert.EqualError(t, err, ErrSheetNameInvalid.Error())
|
2019-05-16 13:36:50 +08:00
|
|
|
|
|
|
|
assert.NoError(t, f.SaveAs(filepath.Join("test", "TestColWidth.xlsx")))
|
|
|
|
convertRowHeightToPixels(0)
|
|
|
|
}
|
|
|
|
|
2022-09-07 00:18:16 +08:00
|
|
|
func TestGetColStyle(t *testing.T) {
|
|
|
|
f := NewFile()
|
|
|
|
styleID, err := f.GetColStyle("Sheet1", "A")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, styleID, 0)
|
|
|
|
|
This closes #1425, breaking changes for sheet name (#1426)
- Checking and return error for invalid sheet name instead of trim invalid characters
- Add error return for the 4 functions: `DeleteSheet`, `GetSheetIndex`, `GetSheetVisible` and `SetSheetName`
- Export new error 4 constants: `ErrSheetNameBlank`, `ErrSheetNameInvalid`, `ErrSheetNameLength` and `ErrSheetNameSingleQuote`
- Rename exported error constant `ErrExistsWorksheet` to `ErrExistsSheet`
- Update unit tests for 90 functions: `AddChart`, `AddChartSheet`, `AddComment`, `AddDataValidation`, `AddPicture`, `AddPictureFromBytes`, `AddPivotTable`, `AddShape`, `AddSparkline`, `AddTable`, `AutoFilter`, `CalcCellValue`, `Cols`, `DeleteChart`, `DeleteComment`, `DeleteDataValidation`, `DeletePicture`, `DeleteSheet`, `DuplicateRow`, `DuplicateRowTo`, `GetCellFormula`, `GetCellHyperLink`, `GetCellRichText`, `GetCellStyle`, `GetCellType`, `GetCellValue`, `GetColOutlineLevel`, `GetCols`, `GetColStyle`, `GetColVisible`, `GetColWidth`, `GetConditionalFormats`, `GetDataValidations`, `GetMergeCells`, `GetPageLayout`, `GetPageMargins`, `GetPicture`, `GetRowHeight`, `GetRowOutlineLevel`, `GetRows`, `GetRowVisible`, `GetSheetIndex`, `GetSheetProps`, `GetSheetVisible`, `GroupSheets`, `InsertCol`, `InsertPageBreak`, `InsertRows`, `MergeCell`, `NewSheet`, `NewStreamWriter`, `ProtectSheet`, `RemoveCol`, `RemovePageBreak`, `RemoveRow`, `Rows`, `SearchSheet`, `SetCellBool`, `SetCellDefault`, `SetCellFloat`, `SetCellFormula`, `SetCellHyperLink`, `SetCellInt`, `SetCellRichText`, `SetCellStr`, `SetCellStyle`, `SetCellValue`, `SetColOutlineLevel`, `SetColStyle`, `SetColVisible`, `SetColWidth`, `SetConditionalFormat`, `SetHeaderFooter`, `SetPageLayout`, `SetPageMargins`, `SetPanes`, `SetRowHeight`, `SetRowOutlineLevel`, `SetRowStyle`, `SetRowVisible`, `SetSheetBackground`, `SetSheetBackgroundFromBytes`, `SetSheetCol`, `SetSheetName`, `SetSheetProps`, `SetSheetRow`, `SetSheetVisible`, `UnmergeCell`, `UnprotectSheet` and
`UnsetConditionalFormat`
- Update documentation of the set style functions
Co-authored-by: guoweikuang <weikuang.guo@shopee.com>
2022-12-23 00:54:40 +08:00
|
|
|
// Test get column style on not exists worksheet
|
2022-09-07 00:18:16 +08:00
|
|
|
_, err = f.GetColStyle("SheetN", "A")
|
|
|
|
assert.EqualError(t, err, "sheet SheetN does not exist")
|
This closes #1425, breaking changes for sheet name (#1426)
- Checking and return error for invalid sheet name instead of trim invalid characters
- Add error return for the 4 functions: `DeleteSheet`, `GetSheetIndex`, `GetSheetVisible` and `SetSheetName`
- Export new error 4 constants: `ErrSheetNameBlank`, `ErrSheetNameInvalid`, `ErrSheetNameLength` and `ErrSheetNameSingleQuote`
- Rename exported error constant `ErrExistsWorksheet` to `ErrExistsSheet`
- Update unit tests for 90 functions: `AddChart`, `AddChartSheet`, `AddComment`, `AddDataValidation`, `AddPicture`, `AddPictureFromBytes`, `AddPivotTable`, `AddShape`, `AddSparkline`, `AddTable`, `AutoFilter`, `CalcCellValue`, `Cols`, `DeleteChart`, `DeleteComment`, `DeleteDataValidation`, `DeletePicture`, `DeleteSheet`, `DuplicateRow`, `DuplicateRowTo`, `GetCellFormula`, `GetCellHyperLink`, `GetCellRichText`, `GetCellStyle`, `GetCellType`, `GetCellValue`, `GetColOutlineLevel`, `GetCols`, `GetColStyle`, `GetColVisible`, `GetColWidth`, `GetConditionalFormats`, `GetDataValidations`, `GetMergeCells`, `GetPageLayout`, `GetPageMargins`, `GetPicture`, `GetRowHeight`, `GetRowOutlineLevel`, `GetRows`, `GetRowVisible`, `GetSheetIndex`, `GetSheetProps`, `GetSheetVisible`, `GroupSheets`, `InsertCol`, `InsertPageBreak`, `InsertRows`, `MergeCell`, `NewSheet`, `NewStreamWriter`, `ProtectSheet`, `RemoveCol`, `RemovePageBreak`, `RemoveRow`, `Rows`, `SearchSheet`, `SetCellBool`, `SetCellDefault`, `SetCellFloat`, `SetCellFormula`, `SetCellHyperLink`, `SetCellInt`, `SetCellRichText`, `SetCellStr`, `SetCellStyle`, `SetCellValue`, `SetColOutlineLevel`, `SetColStyle`, `SetColVisible`, `SetColWidth`, `SetConditionalFormat`, `SetHeaderFooter`, `SetPageLayout`, `SetPageMargins`, `SetPanes`, `SetRowHeight`, `SetRowOutlineLevel`, `SetRowStyle`, `SetRowVisible`, `SetSheetBackground`, `SetSheetBackgroundFromBytes`, `SetSheetCol`, `SetSheetName`, `SetSheetProps`, `SetSheetRow`, `SetSheetVisible`, `UnmergeCell`, `UnprotectSheet` and
`UnsetConditionalFormat`
- Update documentation of the set style functions
Co-authored-by: guoweikuang <weikuang.guo@shopee.com>
2022-12-23 00:54:40 +08:00
|
|
|
// Test get column style with illegal column name
|
2022-09-07 00:18:16 +08:00
|
|
|
_, err = f.GetColStyle("Sheet1", "*")
|
|
|
|
assert.EqualError(t, err, newInvalidColumnNameError("*").Error())
|
This closes #1425, breaking changes for sheet name (#1426)
- Checking and return error for invalid sheet name instead of trim invalid characters
- Add error return for the 4 functions: `DeleteSheet`, `GetSheetIndex`, `GetSheetVisible` and `SetSheetName`
- Export new error 4 constants: `ErrSheetNameBlank`, `ErrSheetNameInvalid`, `ErrSheetNameLength` and `ErrSheetNameSingleQuote`
- Rename exported error constant `ErrExistsWorksheet` to `ErrExistsSheet`
- Update unit tests for 90 functions: `AddChart`, `AddChartSheet`, `AddComment`, `AddDataValidation`, `AddPicture`, `AddPictureFromBytes`, `AddPivotTable`, `AddShape`, `AddSparkline`, `AddTable`, `AutoFilter`, `CalcCellValue`, `Cols`, `DeleteChart`, `DeleteComment`, `DeleteDataValidation`, `DeletePicture`, `DeleteSheet`, `DuplicateRow`, `DuplicateRowTo`, `GetCellFormula`, `GetCellHyperLink`, `GetCellRichText`, `GetCellStyle`, `GetCellType`, `GetCellValue`, `GetColOutlineLevel`, `GetCols`, `GetColStyle`, `GetColVisible`, `GetColWidth`, `GetConditionalFormats`, `GetDataValidations`, `GetMergeCells`, `GetPageLayout`, `GetPageMargins`, `GetPicture`, `GetRowHeight`, `GetRowOutlineLevel`, `GetRows`, `GetRowVisible`, `GetSheetIndex`, `GetSheetProps`, `GetSheetVisible`, `GroupSheets`, `InsertCol`, `InsertPageBreak`, `InsertRows`, `MergeCell`, `NewSheet`, `NewStreamWriter`, `ProtectSheet`, `RemoveCol`, `RemovePageBreak`, `RemoveRow`, `Rows`, `SearchSheet`, `SetCellBool`, `SetCellDefault`, `SetCellFloat`, `SetCellFormula`, `SetCellHyperLink`, `SetCellInt`, `SetCellRichText`, `SetCellStr`, `SetCellStyle`, `SetCellValue`, `SetColOutlineLevel`, `SetColStyle`, `SetColVisible`, `SetColWidth`, `SetConditionalFormat`, `SetHeaderFooter`, `SetPageLayout`, `SetPageMargins`, `SetPanes`, `SetRowHeight`, `SetRowOutlineLevel`, `SetRowStyle`, `SetRowVisible`, `SetSheetBackground`, `SetSheetBackgroundFromBytes`, `SetSheetCol`, `SetSheetName`, `SetSheetProps`, `SetSheetRow`, `SetSheetVisible`, `UnmergeCell`, `UnprotectSheet` and
`UnsetConditionalFormat`
- Update documentation of the set style functions
Co-authored-by: guoweikuang <weikuang.guo@shopee.com>
2022-12-23 00:54:40 +08:00
|
|
|
// Test get column style with invalid sheet name
|
|
|
|
_, err = f.GetColStyle("Sheet:1", "A")
|
|
|
|
assert.EqualError(t, err, ErrSheetNameInvalid.Error())
|
2022-09-07 00:18:16 +08:00
|
|
|
}
|
|
|
|
|
2022-08-31 00:02:48 +08:00
|
|
|
func TestInsertCols(t *testing.T) {
|
2019-05-16 13:36:50 +08:00
|
|
|
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)
|
|
|
|
|
2021-07-28 00:38:09 +08:00
|
|
|
assert.NoError(t, f.SetCellHyperLink(sheet1, "A5", "https://github.com/xuri/excelize", "External"))
|
2019-12-24 01:09:28 +08:00
|
|
|
assert.NoError(t, f.MergeCell(sheet1, "A1", "C3"))
|
2019-05-16 13:36:50 +08:00
|
|
|
|
Breaking change: changed the function signature for 11 exported functions
* Change
`func (f *File) NewConditionalStyle(style string) (int, error)`
to
`func (f *File) NewConditionalStyle(style *Style) (int, error)`
* Change
`func (f *File) NewStyle(style interface{}) (int, error)`
to
`func (f *File) NewStyle(style *Style) (int, error)`
* Change
`func (f *File) AddChart(sheet, cell, opts string, combo ...string) error`
to
`func (f *File) AddChart(sheet, cell string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddChartSheet(sheet, opts string, combo ...string) error`
to
`func (f *File) AddChartSheet(sheet string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddShape(sheet, cell, opts string) error`
to
`func (f *File) AddShape(sheet, cell string, opts *Shape) error`
* Change
`func (f *File) AddPictureFromBytes(sheet, cell, opts, name, extension string, file []byte) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *PictureOptions) error`
* Change
`func (f *File) AddTable(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AddTable(sheet, reference string, opts *TableOptions) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) AutoFilter(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AutoFilter(sheet, reference string, opts *AutoFilterOptions) error`
* Change
`func (f *File) SetPanes(sheet, panes string) error`
to
`func (f *File) SetPanes(sheet string, panes *Panes) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) SetConditionalFormat(sheet, reference, opts string) error`
to
`func (f *File) SetConditionalFormat(sheet, reference string, opts []ConditionalFormatOptions) error`
* Add exported types:
* AutoFilterListOptions
* AutoFilterOptions
* Chart
* ChartAxis
* ChartDimension
* ChartLegend
* ChartLine
* ChartMarker
* ChartPlotArea
* ChartSeries
* ChartTitle
* ConditionalFormatOptions
* PaneOptions
* Panes
* PictureOptions
* Shape
* ShapeColor
* ShapeLine
* ShapeParagraph
* TableOptions
* This added support for set sheet visible as very hidden
* Return error when missing required parameters for set defined name
* Update unit test and comments
2022-12-30 00:50:08 +08:00
|
|
|
assert.NoError(t, f.AutoFilter(sheet1, "A2:B2", &AutoFilterOptions{Column: "B", Expression: "x != blanks"}))
|
2022-08-31 00:02:48 +08:00
|
|
|
assert.NoError(t, f.InsertCols(sheet1, "A", 1))
|
2019-05-16 13:36:50 +08:00
|
|
|
|
This closes #1425, breaking changes for sheet name (#1426)
- Checking and return error for invalid sheet name instead of trim invalid characters
- Add error return for the 4 functions: `DeleteSheet`, `GetSheetIndex`, `GetSheetVisible` and `SetSheetName`
- Export new error 4 constants: `ErrSheetNameBlank`, `ErrSheetNameInvalid`, `ErrSheetNameLength` and `ErrSheetNameSingleQuote`
- Rename exported error constant `ErrExistsWorksheet` to `ErrExistsSheet`
- Update unit tests for 90 functions: `AddChart`, `AddChartSheet`, `AddComment`, `AddDataValidation`, `AddPicture`, `AddPictureFromBytes`, `AddPivotTable`, `AddShape`, `AddSparkline`, `AddTable`, `AutoFilter`, `CalcCellValue`, `Cols`, `DeleteChart`, `DeleteComment`, `DeleteDataValidation`, `DeletePicture`, `DeleteSheet`, `DuplicateRow`, `DuplicateRowTo`, `GetCellFormula`, `GetCellHyperLink`, `GetCellRichText`, `GetCellStyle`, `GetCellType`, `GetCellValue`, `GetColOutlineLevel`, `GetCols`, `GetColStyle`, `GetColVisible`, `GetColWidth`, `GetConditionalFormats`, `GetDataValidations`, `GetMergeCells`, `GetPageLayout`, `GetPageMargins`, `GetPicture`, `GetRowHeight`, `GetRowOutlineLevel`, `GetRows`, `GetRowVisible`, `GetSheetIndex`, `GetSheetProps`, `GetSheetVisible`, `GroupSheets`, `InsertCol`, `InsertPageBreak`, `InsertRows`, `MergeCell`, `NewSheet`, `NewStreamWriter`, `ProtectSheet`, `RemoveCol`, `RemovePageBreak`, `RemoveRow`, `Rows`, `SearchSheet`, `SetCellBool`, `SetCellDefault`, `SetCellFloat`, `SetCellFormula`, `SetCellHyperLink`, `SetCellInt`, `SetCellRichText`, `SetCellStr`, `SetCellStyle`, `SetCellValue`, `SetColOutlineLevel`, `SetColStyle`, `SetColVisible`, `SetColWidth`, `SetConditionalFormat`, `SetHeaderFooter`, `SetPageLayout`, `SetPageMargins`, `SetPanes`, `SetRowHeight`, `SetRowOutlineLevel`, `SetRowStyle`, `SetRowVisible`, `SetSheetBackground`, `SetSheetBackgroundFromBytes`, `SetSheetCol`, `SetSheetName`, `SetSheetProps`, `SetSheetRow`, `SetSheetVisible`, `UnmergeCell`, `UnprotectSheet` and
`UnsetConditionalFormat`
- Update documentation of the set style functions
Co-authored-by: guoweikuang <weikuang.guo@shopee.com>
2022-12-23 00:54:40 +08:00
|
|
|
// Test insert column with illegal cell reference
|
2022-08-31 00:02:48 +08:00
|
|
|
assert.EqualError(t, f.InsertCols(sheet1, "*", 1), newInvalidColumnNameError("*").Error())
|
This closes #1425, breaking changes for sheet name (#1426)
- Checking and return error for invalid sheet name instead of trim invalid characters
- Add error return for the 4 functions: `DeleteSheet`, `GetSheetIndex`, `GetSheetVisible` and `SetSheetName`
- Export new error 4 constants: `ErrSheetNameBlank`, `ErrSheetNameInvalid`, `ErrSheetNameLength` and `ErrSheetNameSingleQuote`
- Rename exported error constant `ErrExistsWorksheet` to `ErrExistsSheet`
- Update unit tests for 90 functions: `AddChart`, `AddChartSheet`, `AddComment`, `AddDataValidation`, `AddPicture`, `AddPictureFromBytes`, `AddPivotTable`, `AddShape`, `AddSparkline`, `AddTable`, `AutoFilter`, `CalcCellValue`, `Cols`, `DeleteChart`, `DeleteComment`, `DeleteDataValidation`, `DeletePicture`, `DeleteSheet`, `DuplicateRow`, `DuplicateRowTo`, `GetCellFormula`, `GetCellHyperLink`, `GetCellRichText`, `GetCellStyle`, `GetCellType`, `GetCellValue`, `GetColOutlineLevel`, `GetCols`, `GetColStyle`, `GetColVisible`, `GetColWidth`, `GetConditionalFormats`, `GetDataValidations`, `GetMergeCells`, `GetPageLayout`, `GetPageMargins`, `GetPicture`, `GetRowHeight`, `GetRowOutlineLevel`, `GetRows`, `GetRowVisible`, `GetSheetIndex`, `GetSheetProps`, `GetSheetVisible`, `GroupSheets`, `InsertCol`, `InsertPageBreak`, `InsertRows`, `MergeCell`, `NewSheet`, `NewStreamWriter`, `ProtectSheet`, `RemoveCol`, `RemovePageBreak`, `RemoveRow`, `Rows`, `SearchSheet`, `SetCellBool`, `SetCellDefault`, `SetCellFloat`, `SetCellFormula`, `SetCellHyperLink`, `SetCellInt`, `SetCellRichText`, `SetCellStr`, `SetCellStyle`, `SetCellValue`, `SetColOutlineLevel`, `SetColStyle`, `SetColVisible`, `SetColWidth`, `SetConditionalFormat`, `SetHeaderFooter`, `SetPageLayout`, `SetPageMargins`, `SetPanes`, `SetRowHeight`, `SetRowOutlineLevel`, `SetRowStyle`, `SetRowVisible`, `SetSheetBackground`, `SetSheetBackgroundFromBytes`, `SetSheetCol`, `SetSheetName`, `SetSheetProps`, `SetSheetRow`, `SetSheetVisible`, `UnmergeCell`, `UnprotectSheet` and
`UnsetConditionalFormat`
- Update documentation of the set style functions
Co-authored-by: guoweikuang <weikuang.guo@shopee.com>
2022-12-23 00:54:40 +08:00
|
|
|
// Test insert column with invalid sheet name
|
|
|
|
assert.EqualError(t, f.InsertCols("Sheet:1", "A", 1), ErrSheetNameInvalid.Error())
|
2022-08-31 00:02:48 +08:00
|
|
|
assert.EqualError(t, f.InsertCols(sheet1, "A", 0), ErrColumnNumber.Error())
|
|
|
|
assert.EqualError(t, f.InsertCols(sheet1, "A", MaxColumns), ErrColumnNumber.Error())
|
|
|
|
assert.EqualError(t, f.InsertCols(sheet1, "A", MaxColumns-10), ErrColumnNumber.Error())
|
|
|
|
|
|
|
|
assert.NoError(t, f.SaveAs(filepath.Join("test", "TestInsertCols.xlsx")))
|
2019-05-16 13:36:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2021-07-28 00:38:09 +08:00
|
|
|
assert.NoError(t, f.SetCellHyperLink(sheet1, "A5", "https://github.com/xuri/excelize", "External"))
|
2019-12-24 01:09:28 +08:00
|
|
|
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"))
|
|
|
|
|
This closes #1425, breaking changes for sheet name (#1426)
- Checking and return error for invalid sheet name instead of trim invalid characters
- Add error return for the 4 functions: `DeleteSheet`, `GetSheetIndex`, `GetSheetVisible` and `SetSheetName`
- Export new error 4 constants: `ErrSheetNameBlank`, `ErrSheetNameInvalid`, `ErrSheetNameLength` and `ErrSheetNameSingleQuote`
- Rename exported error constant `ErrExistsWorksheet` to `ErrExistsSheet`
- Update unit tests for 90 functions: `AddChart`, `AddChartSheet`, `AddComment`, `AddDataValidation`, `AddPicture`, `AddPictureFromBytes`, `AddPivotTable`, `AddShape`, `AddSparkline`, `AddTable`, `AutoFilter`, `CalcCellValue`, `Cols`, `DeleteChart`, `DeleteComment`, `DeleteDataValidation`, `DeletePicture`, `DeleteSheet`, `DuplicateRow`, `DuplicateRowTo`, `GetCellFormula`, `GetCellHyperLink`, `GetCellRichText`, `GetCellStyle`, `GetCellType`, `GetCellValue`, `GetColOutlineLevel`, `GetCols`, `GetColStyle`, `GetColVisible`, `GetColWidth`, `GetConditionalFormats`, `GetDataValidations`, `GetMergeCells`, `GetPageLayout`, `GetPageMargins`, `GetPicture`, `GetRowHeight`, `GetRowOutlineLevel`, `GetRows`, `GetRowVisible`, `GetSheetIndex`, `GetSheetProps`, `GetSheetVisible`, `GroupSheets`, `InsertCol`, `InsertPageBreak`, `InsertRows`, `MergeCell`, `NewSheet`, `NewStreamWriter`, `ProtectSheet`, `RemoveCol`, `RemovePageBreak`, `RemoveRow`, `Rows`, `SearchSheet`, `SetCellBool`, `SetCellDefault`, `SetCellFloat`, `SetCellFormula`, `SetCellHyperLink`, `SetCellInt`, `SetCellRichText`, `SetCellStr`, `SetCellStyle`, `SetCellValue`, `SetColOutlineLevel`, `SetColStyle`, `SetColVisible`, `SetColWidth`, `SetConditionalFormat`, `SetHeaderFooter`, `SetPageLayout`, `SetPageMargins`, `SetPanes`, `SetRowHeight`, `SetRowOutlineLevel`, `SetRowStyle`, `SetRowVisible`, `SetSheetBackground`, `SetSheetBackgroundFromBytes`, `SetSheetCol`, `SetSheetName`, `SetSheetProps`, `SetSheetRow`, `SetSheetVisible`, `UnmergeCell`, `UnprotectSheet` and
`UnsetConditionalFormat`
- Update documentation of the set style functions
Co-authored-by: guoweikuang <weikuang.guo@shopee.com>
2022-12-23 00:54:40 +08:00
|
|
|
// Test remove column with illegal cell reference
|
2021-12-07 00:26:53 +08:00
|
|
|
assert.EqualError(t, f.RemoveCol("Sheet1", "*"), newInvalidColumnNameError("*").Error())
|
This closes #1425, breaking changes for sheet name (#1426)
- Checking and return error for invalid sheet name instead of trim invalid characters
- Add error return for the 4 functions: `DeleteSheet`, `GetSheetIndex`, `GetSheetVisible` and `SetSheetName`
- Export new error 4 constants: `ErrSheetNameBlank`, `ErrSheetNameInvalid`, `ErrSheetNameLength` and `ErrSheetNameSingleQuote`
- Rename exported error constant `ErrExistsWorksheet` to `ErrExistsSheet`
- Update unit tests for 90 functions: `AddChart`, `AddChartSheet`, `AddComment`, `AddDataValidation`, `AddPicture`, `AddPictureFromBytes`, `AddPivotTable`, `AddShape`, `AddSparkline`, `AddTable`, `AutoFilter`, `CalcCellValue`, `Cols`, `DeleteChart`, `DeleteComment`, `DeleteDataValidation`, `DeletePicture`, `DeleteSheet`, `DuplicateRow`, `DuplicateRowTo`, `GetCellFormula`, `GetCellHyperLink`, `GetCellRichText`, `GetCellStyle`, `GetCellType`, `GetCellValue`, `GetColOutlineLevel`, `GetCols`, `GetColStyle`, `GetColVisible`, `GetColWidth`, `GetConditionalFormats`, `GetDataValidations`, `GetMergeCells`, `GetPageLayout`, `GetPageMargins`, `GetPicture`, `GetRowHeight`, `GetRowOutlineLevel`, `GetRows`, `GetRowVisible`, `GetSheetIndex`, `GetSheetProps`, `GetSheetVisible`, `GroupSheets`, `InsertCol`, `InsertPageBreak`, `InsertRows`, `MergeCell`, `NewSheet`, `NewStreamWriter`, `ProtectSheet`, `RemoveCol`, `RemovePageBreak`, `RemoveRow`, `Rows`, `SearchSheet`, `SetCellBool`, `SetCellDefault`, `SetCellFloat`, `SetCellFormula`, `SetCellHyperLink`, `SetCellInt`, `SetCellRichText`, `SetCellStr`, `SetCellStyle`, `SetCellValue`, `SetColOutlineLevel`, `SetColStyle`, `SetColVisible`, `SetColWidth`, `SetConditionalFormat`, `SetHeaderFooter`, `SetPageLayout`, `SetPageMargins`, `SetPanes`, `SetRowHeight`, `SetRowOutlineLevel`, `SetRowStyle`, `SetRowVisible`, `SetSheetBackground`, `SetSheetBackgroundFromBytes`, `SetSheetCol`, `SetSheetName`, `SetSheetProps`, `SetSheetRow`, `SetSheetVisible`, `UnmergeCell`, `UnprotectSheet` and
`UnsetConditionalFormat`
- Update documentation of the set style functions
Co-authored-by: guoweikuang <weikuang.guo@shopee.com>
2022-12-23 00:54:40 +08:00
|
|
|
// Test remove column on not exists worksheet
|
2022-08-28 00:16:41 +08:00
|
|
|
assert.EqualError(t, f.RemoveCol("SheetN", "B"), "sheet SheetN does not exist")
|
This closes #1425, breaking changes for sheet name (#1426)
- Checking and return error for invalid sheet name instead of trim invalid characters
- Add error return for the 4 functions: `DeleteSheet`, `GetSheetIndex`, `GetSheetVisible` and `SetSheetName`
- Export new error 4 constants: `ErrSheetNameBlank`, `ErrSheetNameInvalid`, `ErrSheetNameLength` and `ErrSheetNameSingleQuote`
- Rename exported error constant `ErrExistsWorksheet` to `ErrExistsSheet`
- Update unit tests for 90 functions: `AddChart`, `AddChartSheet`, `AddComment`, `AddDataValidation`, `AddPicture`, `AddPictureFromBytes`, `AddPivotTable`, `AddShape`, `AddSparkline`, `AddTable`, `AutoFilter`, `CalcCellValue`, `Cols`, `DeleteChart`, `DeleteComment`, `DeleteDataValidation`, `DeletePicture`, `DeleteSheet`, `DuplicateRow`, `DuplicateRowTo`, `GetCellFormula`, `GetCellHyperLink`, `GetCellRichText`, `GetCellStyle`, `GetCellType`, `GetCellValue`, `GetColOutlineLevel`, `GetCols`, `GetColStyle`, `GetColVisible`, `GetColWidth`, `GetConditionalFormats`, `GetDataValidations`, `GetMergeCells`, `GetPageLayout`, `GetPageMargins`, `GetPicture`, `GetRowHeight`, `GetRowOutlineLevel`, `GetRows`, `GetRowVisible`, `GetSheetIndex`, `GetSheetProps`, `GetSheetVisible`, `GroupSheets`, `InsertCol`, `InsertPageBreak`, `InsertRows`, `MergeCell`, `NewSheet`, `NewStreamWriter`, `ProtectSheet`, `RemoveCol`, `RemovePageBreak`, `RemoveRow`, `Rows`, `SearchSheet`, `SetCellBool`, `SetCellDefault`, `SetCellFloat`, `SetCellFormula`, `SetCellHyperLink`, `SetCellInt`, `SetCellRichText`, `SetCellStr`, `SetCellStyle`, `SetCellValue`, `SetColOutlineLevel`, `SetColStyle`, `SetColVisible`, `SetColWidth`, `SetConditionalFormat`, `SetHeaderFooter`, `SetPageLayout`, `SetPageMargins`, `SetPanes`, `SetRowHeight`, `SetRowOutlineLevel`, `SetRowStyle`, `SetRowVisible`, `SetSheetBackground`, `SetSheetBackgroundFromBytes`, `SetSheetCol`, `SetSheetName`, `SetSheetProps`, `SetSheetRow`, `SetSheetVisible`, `UnmergeCell`, `UnprotectSheet` and
`UnsetConditionalFormat`
- Update documentation of the set style functions
Co-authored-by: guoweikuang <weikuang.guo@shopee.com>
2022-12-23 00:54:40 +08:00
|
|
|
// Test remove column with invalid sheet name
|
|
|
|
assert.EqualError(t, f.RemoveCol("Sheet:1", "A"), ErrSheetNameInvalid.Error())
|
2019-05-16 13:36:50 +08:00
|
|
|
|
|
|
|
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))
|
|
|
|
}
|