This closes #993, closes #1014

- Fix formula percentages calculated incorrectly
- Make UpdateLinkedValue skip macro sheet
- Fix conditional format bottom N not working
This commit is contained in:
xuri 2021-09-06 00:01:42 +08:00
parent 32b23ef42d
commit 684603befa
No known key found for this signature in database
GPG Key ID: BA5E5BB1C948EDF7
5 changed files with 20 additions and 5 deletions

14
calc.go
View File

@ -975,6 +975,11 @@ func isOperatorPrefixToken(token efp.Token) bool {
return (token.TValue == "-" && token.TType == efp.TokenTypeOperatorPrefix) || (ok && token.TType == efp.TokenTypeOperatorInfix) return (token.TValue == "-" && token.TType == efp.TokenTypeOperatorPrefix) || (ok && token.TType == efp.TokenTypeOperatorInfix)
} }
// isOperand determine if the token is parse operand perand.
func isOperand(token efp.Token) bool {
return token.TType == efp.TokenTypeOperand && (token.TSubType == efp.TokenSubTypeNumber || token.TSubType == efp.TokenSubTypeText)
}
// getDefinedNameRefTo convert defined name to reference range. // getDefinedNameRefTo convert defined name to reference range.
func (f *File) getDefinedNameRefTo(definedNameName string, currentSheet string) (refTo string) { func (f *File) getDefinedNameRefTo(definedNameName string, currentSheet string) (refTo string) {
var workbookRefTo, worksheetRefTo string var workbookRefTo, worksheetRefTo string
@ -1034,8 +1039,15 @@ func (f *File) parseToken(sheet string, token efp.Token, opdStack, optStack *Sta
} }
optStack.Pop() optStack.Pop()
} }
if token.TType == efp.TokenTypeOperatorPostfix && !opdStack.Empty() {
topOpd := opdStack.Pop().(efp.Token)
opd, err := strconv.ParseFloat(topOpd.TValue, 64)
topOpd.TValue = strconv.FormatFloat(opd/100, 'f', -1, 64)
opdStack.Push(topOpd)
return err
}
// opd // opd
if token.TType == efp.TokenTypeOperand && (token.TSubType == efp.TokenSubTypeNumber || token.TSubType == efp.TokenSubTypeText) { if isOperand(token) {
opdStack.Push(token) opdStack.Push(token)
} }
return nil return nil

View File

@ -46,6 +46,8 @@ func TestCalcCellValue(t *testing.T) {
"=2>=1": "TRUE", "=2>=1": "TRUE",
"=2>=3": "FALSE", "=2>=3": "FALSE",
"=1&2": "12", "=1&2": "12",
"=15%": "0.15",
"=1+20%": "1.2",
`="A"="A"`: "TRUE", `="A"="A"`: "TRUE",
`="A"<>"A"`: "FALSE", `="A"<>"A"`: "FALSE",
// Engineering Functions // Engineering Functions

View File

@ -230,7 +230,7 @@ func TestAddChartSheet(t *testing.T) {
f.SetActiveSheet(sheetIdx) f.SetActiveSheet(sheetIdx)
// Test cell value on chartsheet // Test cell value on chartsheet
assert.EqualError(t, f.SetCellValue("Chart1", "A1", true), "sheet Chart1 is chart sheet") assert.EqualError(t, f.SetCellValue("Chart1", "A1", true), "sheet Chart1 is not a worksheet")
// Test add chartsheet on already existing name sheet // Test add chartsheet on already existing name sheet
assert.EqualError(t, f.AddChartSheet("Sheet1", `{"type":"col3DClustered","series":[{"name":"Sheet1!$A$2","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$2:$D$2"},{"name":"Sheet1!$A$3","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$3:$D$3"},{"name":"Sheet1!$A$4","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$4:$D$4"}],"title":{"name":"Fruit 3D Clustered Column Chart"}}`), ErrExistsWorksheet.Error()) assert.EqualError(t, f.AddChartSheet("Sheet1", `{"type":"col3DClustered","series":[{"name":"Sheet1!$A$2","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$2:$D$2"},{"name":"Sheet1!$A$3","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$3:$D$3"},{"name":"Sheet1!$A$4","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$4:$D$4"}],"title":{"name":"Fruit 3D Clustered Column Chart"}}`), ErrExistsWorksheet.Error())
// Test with unsupported chart type // Test with unsupported chart type

View File

@ -204,8 +204,8 @@ func (f *File) workSheetReader(sheet string) (ws *xlsxWorksheet, err error) {
ws = worksheet.(*xlsxWorksheet) ws = worksheet.(*xlsxWorksheet)
return return
} }
if strings.HasPrefix(name, "xl/chartsheets") { if strings.HasPrefix(name, "xl/chartsheets") || strings.HasPrefix(name, "xl/macrosheet") {
err = fmt.Errorf("sheet %s is chart sheet", sheet) err = fmt.Errorf("sheet %s is not a worksheet", sheet)
return return
} }
ws = new(xlsxWorksheet) ws = new(xlsxWorksheet)
@ -367,7 +367,7 @@ func (f *File) UpdateLinkedValue() error {
for _, name := range f.GetSheetList() { for _, name := range f.GetSheetList() {
ws, err := f.workSheetReader(name) ws, err := f.workSheetReader(name)
if err != nil { if err != nil {
if err.Error() == fmt.Sprintf("sheet %s is chart sheet", trimSheetName(name)) { if err.Error() == fmt.Sprintf("sheet %s is not a worksheet", trimSheetName(name)) {
continue continue
} }
return err return err

View File

@ -3011,6 +3011,7 @@ func drawCondFmtCellIs(p int, ct string, format *formatConditional) *xlsxCfRule
func drawCondFmtTop10(p int, ct string, format *formatConditional) *xlsxCfRule { func drawCondFmtTop10(p int, ct string, format *formatConditional) *xlsxCfRule {
c := &xlsxCfRule{ c := &xlsxCfRule{
Priority: p + 1, Priority: p + 1,
Bottom: format.Type == "bottom",
Type: validType[format.Type], Type: validType[format.Type],
Rank: 10, Rank: 10,
DxfID: &format.Format, DxfID: &format.Format,