-
Notifications
You must be signed in to change notification settings - Fork 0
Formula cells should inherit number format from referenced cells #184
Copy link
Copy link
Open
Description
Problem
When a formula references cells with number formatting (e.g., currency), Excel automatically inherits that formatting for the result cell. Currently, xl does not do this - formula cells get General format regardless of their inputs.
Example:
[
{"op": "put", "ref": "B2", "value": 1000000, "format": "currency"},
{"op": "put", "ref": "B3", "value": 600000, "format": "currency"},
{"op": "putf", "ref": "B4", "value": "=B2-B3"}
]Current behavior: B4 shows 400000 (General format)
Expected behavior: B4 shows $400,000.00 (inherited Currency format)
Workaround
Explicitly style formula cells:
{"op": "putf", "ref": "B4", "value": "=B2-B3"},
{"op": "style", "range": "B4", "numFormat": "currency"}Proposed Solution
- Parse the formula to extract cell references
- Look up styles of referenced cells
- Determine "dominant" format using Excel's precedence rules:
- Currency > Percent > Date > Decimal > General
- If mixed incompatible formats, use General
- Apply the dominant format to the formula cell
Scope
This would affect:
BatchParser.applyPutFormula()WriteCommands.putFormula()- Potentially the streaming writer
Priority
Nice-to-have for Excel parity, but the explicit styling workaround is reasonable for now.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels