Compatibility improvement
This commit is contained in:
parent
75d66a03f3
commit
a34d3b8c86
2
chart.go
2
chart.go
|
@ -1845,7 +1845,7 @@ func (f *File) addDrawingChart(sheet, drawingXML, cell string, width, height, rI
|
|||
graphicFrame := xlsxGraphicFrame{
|
||||
NvGraphicFramePr: xlsxNvGraphicFramePr{
|
||||
CNvPr: &xlsxCNvPr{
|
||||
ID: f.countCharts() + f.countMedia() + 1,
|
||||
ID: len(content.OneCellAnchor) + len(content.TwoCellAnchor) + 2,
|
||||
Name: "Chart " + strconv.Itoa(cNvPrID),
|
||||
},
|
||||
},
|
||||
|
|
10
col.go
10
col.go
|
@ -10,6 +10,7 @@
|
|||
package excelize
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math"
|
||||
"strings"
|
||||
)
|
||||
|
@ -112,19 +113,22 @@ func (f *File) GetColOutlineLevel(sheet, col string) (uint8, error) {
|
|||
for c := range xlsx.Cols.Col {
|
||||
colData := &xlsx.Cols.Col[c]
|
||||
if colData.Min <= colNum && colNum <= colData.Max {
|
||||
level = colData.OutlineLevel
|
||||
level = colData.OutlineLevel + 1
|
||||
}
|
||||
}
|
||||
return level, err
|
||||
}
|
||||
|
||||
// SetColOutlineLevel provides a function to set outline level of a single
|
||||
// column by given worksheet name and column name. For example, set outline
|
||||
// level of column D in Sheet1 to 2:
|
||||
// column by given worksheet name and column name. The value of parameter
|
||||
// 'level' is 1-7. For example, set outline level of column D in Sheet1 to 2:
|
||||
//
|
||||
// err := f.SetColOutlineLevel("Sheet1", "D", 2)
|
||||
//
|
||||
func (f *File) SetColOutlineLevel(sheet, col string, level uint8) error {
|
||||
if level > 7 || level < 1 {
|
||||
return errors.New("invalid outline level")
|
||||
}
|
||||
colNum, err := ColumnNameToNumber(col)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
35
col_test.go
35
col_test.go
|
@ -10,9 +10,7 @@ import (
|
|||
func TestColumnVisibility(t *testing.T) {
|
||||
t.Run("TestBook1", func(t *testing.T) {
|
||||
f, err := prepareTestBook1()
|
||||
if !assert.NoError(t, err) {
|
||||
t.FailNow()
|
||||
}
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.NoError(t, f.SetColVisible("Sheet1", "F", false))
|
||||
assert.NoError(t, f.SetColVisible("Sheet1", "F", true))
|
||||
|
@ -38,9 +36,7 @@ func TestColumnVisibility(t *testing.T) {
|
|||
|
||||
t.Run("TestBook3", func(t *testing.T) {
|
||||
f, err := prepareTestBook3()
|
||||
if !assert.NoError(t, err) {
|
||||
t.FailNow()
|
||||
}
|
||||
assert.NoError(t, err)
|
||||
f.GetColVisible("Sheet1", "B")
|
||||
})
|
||||
}
|
||||
|
@ -49,12 +45,14 @@ func TestOutlineLevel(t *testing.T) {
|
|||
f := NewFile()
|
||||
f.GetColOutlineLevel("Sheet1", "D")
|
||||
f.NewSheet("Sheet2")
|
||||
f.SetColOutlineLevel("Sheet1", "D", 4)
|
||||
assert.NoError(t, f.SetColOutlineLevel("Sheet1", "D", 4))
|
||||
f.GetColOutlineLevel("Sheet1", "D")
|
||||
f.GetColOutlineLevel("Shee2", "A")
|
||||
f.SetColWidth("Sheet2", "A", "D", 13)
|
||||
f.SetColOutlineLevel("Sheet2", "B", 2)
|
||||
f.SetRowOutlineLevel("Sheet1", 2, 250)
|
||||
assert.NoError(t, f.SetColWidth("Sheet2", "A", "D", 13))
|
||||
assert.NoError(t, f.SetColOutlineLevel("Sheet2", "B", 2))
|
||||
assert.NoError(t, f.SetRowOutlineLevel("Sheet1", 2, 7))
|
||||
assert.EqualError(t, f.SetColOutlineLevel("Sheet1", "D", 8), "invalid outline level")
|
||||
assert.EqualError(t, f.SetRowOutlineLevel("Sheet1", 2, 8), "invalid outline level")
|
||||
|
||||
// Test set and get column outline level with illegal cell coordinates.
|
||||
assert.EqualError(t, f.SetColOutlineLevel("Sheet1", "*", 1), `invalid column name "*"`)
|
||||
|
@ -67,7 +65,7 @@ func TestOutlineLevel(t *testing.T) {
|
|||
assert.EqualError(t, f.SetRowOutlineLevel("Sheet1", 0, 1), "invalid row number 0")
|
||||
level, err := f.GetRowOutlineLevel("Sheet1", 2)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, uint8(250), level)
|
||||
assert.Equal(t, uint8(7), level)
|
||||
|
||||
_, err = f.GetRowOutlineLevel("Sheet1", 0)
|
||||
assert.EqualError(t, err, `invalid row number 0`)
|
||||
|
@ -76,15 +74,10 @@ func TestOutlineLevel(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.Equal(t, uint8(0), level)
|
||||
|
||||
err = f.SaveAs(filepath.Join("test", "TestOutlineLevel.xlsx"))
|
||||
if !assert.NoError(t, err) {
|
||||
t.FailNow()
|
||||
}
|
||||
assert.NoError(t, f.SaveAs(filepath.Join("test", "TestOutlineLevel.xlsx")))
|
||||
|
||||
f, err = OpenFile(filepath.Join("test", "Book1.xlsx"))
|
||||
if !assert.NoError(t, err) {
|
||||
t.FailNow()
|
||||
}
|
||||
assert.NoError(t, err)
|
||||
f.SetColOutlineLevel("Sheet2", "B", 2)
|
||||
}
|
||||
|
||||
|
@ -138,11 +131,7 @@ func TestInsertCol(t *testing.T) {
|
|||
f.SetCellHyperLink(sheet1, "A5", "https://github.com/360EntSecGroup-Skylar/excelize", "External")
|
||||
f.MergeCell(sheet1, "A1", "C3")
|
||||
|
||||
err := f.AutoFilter(sheet1, "A2", "B2", `{"column":"B","expression":"x != blanks"}`)
|
||||
if !assert.NoError(t, err) {
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
assert.NoError(t, f.AutoFilter(sheet1, "A2", "B2", `{"column":"B","expression":"x != blanks"}`))
|
||||
assert.NoError(t, f.InsertCol(sheet1, "A"))
|
||||
|
||||
// Test insert column with illegal cell coordinates.
|
||||
|
|
|
@ -272,7 +272,7 @@ func (f *File) addDrawingPicture(sheet, drawingXML, cell, file string, width, he
|
|||
twoCellAnchor.To = &to
|
||||
pic := xlsxPic{}
|
||||
pic.NvPicPr.CNvPicPr.PicLocks.NoChangeAspect = formatSet.NoChangeAspect
|
||||
pic.NvPicPr.CNvPr.ID = f.countCharts() + f.countMedia() + 1
|
||||
pic.NvPicPr.CNvPr.ID = len(content.OneCellAnchor) + len(content.TwoCellAnchor) + 2
|
||||
pic.NvPicPr.CNvPr.Descr = file
|
||||
pic.NvPicPr.CNvPr.Name = "Picture " + strconv.Itoa(cNvPrID)
|
||||
if hyperlinkRID != 0 {
|
||||
|
|
8
rows.go
8
rows.go
|
@ -11,6 +11,7 @@ package excelize
|
|||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
|
@ -257,8 +258,8 @@ func (f *File) GetRowVisible(sheet string, row int) (bool, error) {
|
|||
}
|
||||
|
||||
// SetRowOutlineLevel provides a function to set outline level number of a
|
||||
// single row by given worksheet name and Excel row number. For example,
|
||||
// outline row 2 in Sheet1 to level 1:
|
||||
// single row by given worksheet name and Excel row number. The value of
|
||||
// parameter 'level' is 1-7. For example, outline row 2 in Sheet1 to level 1:
|
||||
//
|
||||
// err := f.SetRowOutlineLevel("Sheet1", 2, 1)
|
||||
//
|
||||
|
@ -266,6 +267,9 @@ func (f *File) SetRowOutlineLevel(sheet string, row int, level uint8) error {
|
|||
if row < 1 {
|
||||
return newInvalidRowNumberError(row)
|
||||
}
|
||||
if level > 7 || level < 1 {
|
||||
return errors.New("invalid outline level")
|
||||
}
|
||||
xlsx, err := f.workSheetReader(sheet)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
10
sparkline.go
10
sparkline.go
|
@ -429,11 +429,6 @@ func (f *File) AddSparkline(sheet string, opt *SparklineOption) error {
|
|||
return err
|
||||
}
|
||||
for idx, ext := range decodeExtLst.Ext {
|
||||
// hack: add back missing namespace
|
||||
decodeExtLst.Ext[idx].XMLNSX14 = decodeExtLst.Ext[idx].X14
|
||||
decodeExtLst.Ext[idx].XMLNSX15 = decodeExtLst.Ext[idx].X15
|
||||
decodeExtLst.Ext[idx].XMLNSX14 = ""
|
||||
decodeExtLst.Ext[idx].XMLNSX15 = ""
|
||||
if ext.URI == ExtURISparklineGroups {
|
||||
decodeSparklineGroups := decodeX14SparklineGroups{}
|
||||
_ = xml.Unmarshal([]byte(ext.Content), &decodeSparklineGroups)
|
||||
|
@ -458,9 +453,8 @@ func (f *File) AddSparkline(sheet string, opt *SparklineOption) error {
|
|||
}
|
||||
sparklineGroupsBytes, _ := xml.Marshal(groups)
|
||||
extLst := xlsxWorksheetExt{
|
||||
XMLNSX14: NameSpaceSpreadSheetX14,
|
||||
URI: ExtURISparklineGroups,
|
||||
Content: string(sparklineGroupsBytes),
|
||||
URI: ExtURISparklineGroups,
|
||||
Content: string(sparklineGroupsBytes),
|
||||
}
|
||||
extBytes, _ := xml.Marshal(extLst)
|
||||
ws.ExtLst.Ext = string(extBytes)
|
||||
|
|
BIN
test/Book1.xlsx
BIN
test/Book1.xlsx
Binary file not shown.
|
@ -293,9 +293,10 @@ type cAutoTitleDeleted struct {
|
|||
type cView3D struct {
|
||||
RotX *attrValInt `xml:"rotX"`
|
||||
RotY *attrValInt `xml:"rotY"`
|
||||
RAngAx *attrValInt `xml:"rAngAx"`
|
||||
DepthPercent *attrValInt `xml:"depthPercent"`
|
||||
Perspective *attrValInt `xml:"perspective"`
|
||||
RAngAx *attrValInt `xml:"rAngAx"`
|
||||
ExtLst *xlsxExtLst `xml:"extLst"`
|
||||
}
|
||||
|
||||
// cPlotArea directly maps the plotArea element. This element specifies the
|
||||
|
|
10
xmlStyles.go
10
xmlStyles.go
|
@ -85,9 +85,6 @@ type xlsxFonts struct {
|
|||
// xlsxFont directly maps the font element. This element defines the
|
||||
// properties for one of the fonts used in this workbook.
|
||||
type xlsxFont struct {
|
||||
Name *attrValString `xml:"name"`
|
||||
Charset *attrValInt `xml:"charset"`
|
||||
Family *attrValInt `xml:"family"`
|
||||
B *bool `xml:"b,omitempty"`
|
||||
I *bool `xml:"i,omitempty"`
|
||||
Strike *bool `xml:"strike,omitempty"`
|
||||
|
@ -95,9 +92,12 @@ type xlsxFont struct {
|
|||
Shadow *bool `xml:"shadow,omitempty"`
|
||||
Condense *bool `xml:"condense,omitempty"`
|
||||
Extend *bool `xml:"extend,omitempty"`
|
||||
Color *xlsxColor `xml:"color"`
|
||||
Sz *attrValFloat `xml:"sz"`
|
||||
U *attrValString `xml:"u"`
|
||||
Sz *attrValFloat `xml:"sz"`
|
||||
Color *xlsxColor `xml:"color"`
|
||||
Name *attrValString `xml:"name"`
|
||||
Family *attrValInt `xml:"family"`
|
||||
Charset *attrValInt `xml:"charset"`
|
||||
Scheme *attrValString `xml:"scheme"`
|
||||
}
|
||||
|
||||
|
|
|
@ -629,13 +629,9 @@ type xlsxLegacyDrawing struct {
|
|||
|
||||
// xlsxWorksheetExt directly maps the ext element in the worksheet.
|
||||
type xlsxWorksheetExt struct {
|
||||
XMLName xml.Name `xml:"ext"`
|
||||
XMLNSX14 string `xml:"xmlns:x14,attr,omitempty"`
|
||||
XMLNSX15 string `xml:"xmlns:x15,attr,omitempty"`
|
||||
X14 string `xml:"x14,attr,omitempty"`
|
||||
X15 string `xml:"x15,attr,omitempty"`
|
||||
URI string `xml:"uri,attr"`
|
||||
Content string `xml:",innerxml"`
|
||||
XMLName xml.Name `xml:"ext"`
|
||||
URI string `xml:"uri,attr"`
|
||||
Content string `xml:",innerxml"`
|
||||
}
|
||||
|
||||
// decodeWorksheetExt directly maps the ext element.
|
||||
|
|
Loading…
Reference in New Issue