未验证 提交 afb2d27c 编写于 作者: xurime's avatar xurime 提交者: GitHub

This fix formula calculation accuracy issue and panic when set pane

- Fix `GROWTH` and `TREND` calculation accuracy issue
- Fix panic when add pane on empty sheet views worksheet
- New exported constants `MinFontSize`
上级 63adac25
......@@ -4579,8 +4579,7 @@ func newFormulaArgMatrix(numMtx [][]float64) (arg [][]formulaArg) {
for r, row := range numMtx {
arg = append(arg, make([]formulaArg, len(row)))
for c, cell := range row {
decimal, _ := big.NewFloat(cell).SetPrec(15).Float64()
arg[r][c] = newNumberFormulaArg(decimal)
arg[r][c] = newNumberFormulaArg(cell)
}
}
return
......
......@@ -4518,17 +4518,17 @@ func TestCalcGROWTHandTREND(t *testing.T) {
formulaList := map[string]string{
"=GROWTH(A2:B2)": "1",
"=GROWTH(B2:B5,A2:A5,A8:A10)": "160",
"=GROWTH(B2:B5,A2:A5,A8:A10,FALSE)": "467.84375",
"=GROWTH(B2:B5,A2:A5,A8:A10,FALSE)": "467.842838114059",
"=GROWTH(A4:A5,A2:B3,A8:A10,FALSE)": "",
"=GROWTH(A3:A5,A2:B4,A2:B3)": "2",
"=GROWTH(A4:A5,A2:B3)": "",
"=GROWTH(A2:B2,A2:B3)": "",
"=GROWTH(A2:B2,A2:B3,A2:B3,FALSE)": "1.28399658203125",
"=GROWTH(A2:B2,A2:B3,A2:B3,FALSE)": "1.28402541668774",
"=GROWTH(A2:B2,A4:B5,A4:B5,FALSE)": "1",
"=GROWTH(A3:C3,A2:C3,A2:B3)": "2",
"=TREND(A2:B2)": "1",
"=TREND(B2:B5,A2:A5,A8:A10)": "95",
"=TREND(B2:B5,A2:A5,A8:A10,FALSE)": "81.66796875",
"=TREND(B2:B5,A2:A5,A8:A10,FALSE)": "81.6666666666667",
"=TREND(A4:A5,A2:B3,A8:A10,FALSE)": "",
"=TREND(A4:A5,A2:B3,A2:B3,FALSE)": "1.5",
"=TREND(A3:A5,A2:B4,A2:B3)": "2",
......
......@@ -102,7 +102,7 @@ var (
ErrMaxRows = errors.New("row number exceeds maximum limit")
// ErrMaxRowHeight defined the error message on receive an invalid row
// height.
ErrMaxRowHeight = errors.New("the height of the row must be smaller than or equal to 409 points")
ErrMaxRowHeight = fmt.Errorf("the height of the row must be smaller than or equal to %d points", MaxRowHeight)
// ErrImgExt defined the error message on receive an unsupported image
// extension.
ErrImgExt = errors.New("unsupported image extension")
......@@ -145,9 +145,9 @@ var (
ErrCustomNumFmt = errors.New("custom number format can not be empty")
// ErrFontLength defined the error message on the length of the font
// family name overflow.
ErrFontLength = errors.New("the length of the font family name must be smaller than or equal to 31")
ErrFontLength = fmt.Errorf("the length of the font family name must be smaller than or equal to %d", MaxFontFamilyLength)
// ErrFontSize defined the error message on the size of the font is invalid.
ErrFontSize = errors.New("font size must be between 1 and 409 points")
ErrFontSize = fmt.Errorf("font size must be between %d and %d points", MinFontSize, MaxFontSize)
// ErrSheetIdx defined the error message on receive the invalid worksheet
// index.
ErrSheetIdx = errors.New("invalid worksheet index")
......@@ -161,7 +161,7 @@ var (
ErrGroupSheets = errors.New("group worksheet must contain an active worksheet")
// ErrDataValidationFormulaLength defined the error message for receiving a
// data validation formula length that exceeds the limit.
ErrDataValidationFormulaLength = errors.New("data validation must be 0-255 characters")
ErrDataValidationFormulaLength = fmt.Errorf("data validation must be 0-%d characters", MaxFieldLength)
// ErrDataValidationRange defined the error message on set decimal range
// exceeds limit.
ErrDataValidationRange = errors.New("data validation range exceeds limit")
......
......@@ -773,6 +773,9 @@ func (f *File) SetPanes(sheet, panes string) error {
if fs.Freeze {
p.State = "frozen"
}
if ws.SheetViews == nil {
ws.SheetViews = &xlsxSheetViews{SheetView: []xlsxSheetView{{}}}
}
ws.SheetViews.SheetView[len(ws.SheetViews.SheetView)-1].Pane = p
if !(fs.Freeze) && !(fs.Split) {
if len(ws.SheetViews.SheetView) > 0 {
......
......@@ -104,6 +104,12 @@ func TestSetPane(t *testing.T) {
assert.NoError(t, f.SetPanes("Panes 4", ""))
assert.EqualError(t, f.SetPanes("SheetN", ""), "sheet SheetN is not exist")
assert.NoError(t, f.SaveAs(filepath.Join("test", "TestSetPane.xlsx")))
// Test add pane on empty sheet views worksheet
f = NewFile()
f.checked = nil
f.Sheet.Delete("xl/worksheets/sheet1.xml")
f.Pkg.Store("xl/worksheets/sheet1.xml", []byte(`<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><sheetData/></worksheet>`))
assert.NoError(t, f.SetPanes("Sheet1", `{"freeze":true,"split":false,"x_split":1,"y_split":0,"top_left_cell":"B1","active_pane":"topRight","panes":[{"sqref":"K16","active_cell":"K16","pane":"topRight"}]}`))
}
func TestPageLayoutOption(t *testing.T) {
......
......@@ -2042,7 +2042,7 @@ func (f *File) getFontID(styleSheet *xlsxStyleSheet, style *Style) (fontID int)
// settings.
func (f *File) newFont(style *Style) *xlsxFont {
fontUnderlineType := map[string]string{"single": "single", "double": "double"}
if style.Font.Size < 1 {
if style.Font.Size < MinFontSize {
style.Font.Size = 11
}
if style.Font.Color == "" {
......
......@@ -107,6 +107,7 @@ const (
MaxFieldLength = 255
MaxColumnWidth = 255
MaxRowHeight = 409
MinFontSize = 1
TotalRows = 1048576
TotalColumns = 16384
TotalSheetHyperlinks = 65529
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册