pycel
pycel copied to clipboard
accounting for white spaces in ranges
- [x] closes #136
- [x] tests added / passed
- [x] passes
tox
Previously, we had the following behavior for variations of '=SUM(Sheet2!A1:A2)'
:
from openpyxl import Workbook
wb = Workbook()
wb.create_sheet('Sheet1')
wb.create_sheet('Sheet2')
ws = wb['Sheet2']
ws['A1'], ws['A2'] = 1, 2
ws = wb['Sheet1']
ws['A1'] = f'=SUM(\'Sheet2\' !A1:A2)' # FAILED - this one is a syntax error in Excel too, but you're prompted to correct it
ws['A2'] = f'=SUM(\'Sheet2\'! A1:A2)' # #NAME?
ws['A3'] = f'=SUM(\'Sheet2\'!A1 :A2)' # FAILED
ws['A4'] = f'=SUM(\'Sheet2\'!A1: A2)' # #NAME?
ws['A5'] = f'=SUM(\'Sheet2\'!A1 : A2)' # FAILED
Now these should all work (i.e., evaluate to 3). They'll also work with multiple whitespaces because the openpyxl tokenizer tokenizes it the same way.
I had to add the any(c in '!:' for c in (last_token.value[-1], next_token.value[0])
condition because without it other tests fail - like this possibility '=SUM((A:A A1:B1))'
Codecov Report
Merging #137 (a967e2c) into master (6ce2bc2) will not change coverage. The diff coverage is
100.00%
.
@@ Coverage Diff @@
## master #137 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 17 17
Lines 3757 3766 +9
Branches 912 914 +2
=========================================
+ Hits 3757 3766 +9
Impacted Files | Coverage Δ | |
---|---|---|
src/pycel/excelformula.py | 100.00% <100.00%> (ø) |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update 6ce2bc2...a967e2c. Read the comment docs.