Skip to content

Commit 684603b

Browse files
committed
This closes qax-os#993, closes qax-os#1014
- Fix formula percentages calculated incorrectly - Make UpdateLinkedValue skip macro sheet - Fix conditional format bottom N not working
1 parent 32b23ef commit 684603b

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

calc.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,11 @@ func isOperatorPrefixToken(token efp.Token) bool {
975975
return (token.TValue == "-" && token.TType == efp.TokenTypeOperatorPrefix) || (ok && token.TType == efp.TokenTypeOperatorInfix)
976976
}
977977

978+
// isOperand determine if the token is parse operand perand.
979+
func isOperand(token efp.Token) bool {
980+
return token.TType == efp.TokenTypeOperand && (token.TSubType == efp.TokenSubTypeNumber || token.TSubType == efp.TokenSubTypeText)
981+
}
982+
978983
// getDefinedNameRefTo convert defined name to reference range.
979984
func (f *File) getDefinedNameRefTo(definedNameName string, currentSheet string) (refTo string) {
980985
var workbookRefTo, worksheetRefTo string
@@ -1034,8 +1039,15 @@ func (f *File) parseToken(sheet string, token efp.Token, opdStack, optStack *Sta
10341039
}
10351040
optStack.Pop()
10361041
}
1042+
if token.TType == efp.TokenTypeOperatorPostfix && !opdStack.Empty() {
1043+
topOpd := opdStack.Pop().(efp.Token)
1044+
opd, err := strconv.ParseFloat(topOpd.TValue, 64)
1045+
topOpd.TValue = strconv.FormatFloat(opd/100, 'f', -1, 64)
1046+
opdStack.Push(topOpd)
1047+
return err
1048+
}
10371049
// opd
1038-
if token.TType == efp.TokenTypeOperand && (token.TSubType == efp.TokenSubTypeNumber || token.TSubType == efp.TokenSubTypeText) {
1050+
if isOperand(token) {
10391051
opdStack.Push(token)
10401052
}
10411053
return nil

calc_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ func TestCalcCellValue(t *testing.T) {
4646
"=2>=1": "TRUE",
4747
"=2>=3": "FALSE",
4848
"=1&2": "12",
49+
"=15%": "0.15",
50+
"=1+20%": "1.2",
4951
`="A"="A"`: "TRUE",
5052
`="A"<>"A"`: "FALSE",
5153
// Engineering Functions

chart_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ func TestAddChartSheet(t *testing.T) {
230230
f.SetActiveSheet(sheetIdx)
231231

232232
// Test cell value on chartsheet
233-
assert.EqualError(t, f.SetCellValue("Chart1", "A1", true), "sheet Chart1 is chart sheet")
233+
assert.EqualError(t, f.SetCellValue("Chart1", "A1", true), "sheet Chart1 is not a worksheet")
234234
// Test add chartsheet on already existing name sheet
235235
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())
236236
// Test with unsupported chart type

excelize.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ func (f *File) workSheetReader(sheet string) (ws *xlsxWorksheet, err error) {
204204
ws = worksheet.(*xlsxWorksheet)
205205
return
206206
}
207-
if strings.HasPrefix(name, "xl/chartsheets") {
208-
err = fmt.Errorf("sheet %s is chart sheet", sheet)
207+
if strings.HasPrefix(name, "xl/chartsheets") || strings.HasPrefix(name, "xl/macrosheet") {
208+
err = fmt.Errorf("sheet %s is not a worksheet", sheet)
209209
return
210210
}
211211
ws = new(xlsxWorksheet)
@@ -367,7 +367,7 @@ func (f *File) UpdateLinkedValue() error {
367367
for _, name := range f.GetSheetList() {
368368
ws, err := f.workSheetReader(name)
369369
if err != nil {
370-
if err.Error() == fmt.Sprintf("sheet %s is chart sheet", trimSheetName(name)) {
370+
if err.Error() == fmt.Sprintf("sheet %s is not a worksheet", trimSheetName(name)) {
371371
continue
372372
}
373373
return err

styles.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3011,6 +3011,7 @@ func drawCondFmtCellIs(p int, ct string, format *formatConditional) *xlsxCfRule
30113011
func drawCondFmtTop10(p int, ct string, format *formatConditional) *xlsxCfRule {
30123012
c := &xlsxCfRule{
30133013
Priority: p + 1,
3014+
Bottom: format.Type == "bottom",
30143015
Type: validType[format.Type],
30153016
Rank: 10,
30163017
DxfID: &format.Format,

0 commit comments

Comments
 (0)