Skip to content

Commit 361a421

Browse files
authored
Merge pull request #13 from PLPeeters/bugfix/column-to-number
Fix `column_to_number` being incorrect for files with more than 26 columns with big thanks!
2 parents 5029ba4 + 0f15592 commit 361a421

File tree

17 files changed

+203
-183
lines changed

17 files changed

+203
-183
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
- name: test
3030
run: |
3131
pip freeze
32-
nosetests --verbosity=3 --with-coverage --cover-package pyexcel_xlsxr --cover-package tests tests --with-doctest --doctest-extension=.rst README.rst pyexcel_xlsxr
32+
coverage run -m --source=pyexcel_xlsxr pytest && coverage report --show-missing
3333
- name: Upload coverage
3434
uses: codecov/codecov-action@v1
3535
with:

CONTRIBUTORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
In alphabetical order:
77

88
* `Mark Skelton <https://github.com/mtskelton>`_
9+
* `Pierre-Louis Peeters <https://github.com/PLPeeters>`_

changelog.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ name: pyexcel-xlsxr
22
organisation: pyexcel
33
releases:
44
- changes:
5-
- action: Updated
5+
- action: Fixed
6+
details:
7+
- 'Fix reading of files with more than 26 columns'
8+
date: 30.10.2025
9+
version: 0.6.2
10+
- action: Updated
611
details:
712
- '#9: Potential fix for incorrect reading of data with empty cells when used with pyexcel '
813
date: 11.11.2024

lint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
pip install flake8
2-
flake8 --exclude=.moban.d,docs,setup.py --builtins=unicode,xrange,long . && python setup.py checkdocs
2+
flake8 --exclude=.moban.d,docs,setup.py,.venv --builtins=unicode,xrange,long . && python setup.py checkdocs

pyexcel_xlsxr/__init__.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
"""
2-
pyexcel_xlsxr
3-
~~~~~~~~~~~~~~~~~~~
4-
The lower level xlsx file format handler using lxml
5-
:copyright: (c) 2015-2020 by Onni Software Ltd & its contributors
6-
:license: New BSD License
2+
pyexcel_xlsxr
3+
~~~~~~~~~~~~~~~~~~~
4+
The lower level xlsx file format handler using lxml
5+
:copyright: (c) 2015-2020 by Onni Software Ltd & its contributors
6+
:license: New BSD License
77
"""
8+
89
from pyexcel_io.io import get_data as read_data
910
from pyexcel_io.io import isstream
1011
from pyexcel_io.plugins import IOPluginInfoChainV2

pyexcel_xlsxr/_version.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
__version__ = '0.6.1'
2-
__author__ = 'C.W.'
1+
__version__ = "0.6.1"
2+
__author__ = "C.W."

pyexcel_xlsxr/messy_xlsx.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import re
33
import zipfile
44
from datetime import time, datetime, timedelta
5+
from functools import cache
56

67
from lxml import etree
78
from pyexcel_io._compact import OrderedDict
@@ -182,12 +183,16 @@ def __repr__(self):
182183
return str(self.value)
183184

184185

186+
@cache
185187
def column_to_number(column):
186-
column = re.sub("[^A-Z]", "", column)
187-
cl = len(column) - 1
188-
return sum(
189-
[(ord(c.upper()) - 64) + (26 * (cl - i)) for i, c in enumerate(column)]
190-
)
188+
column = re.sub(r"[^A-Z]", "", column.upper())
189+
190+
result = 0
191+
192+
for index, c in enumerate(column):
193+
result = result * 26 + (ord(c) - ord("A") + 1)
194+
195+
return result
191196

192197

193198
def parse_row(row_xml_string, book):
@@ -338,10 +343,10 @@ def parse_book_properties(book_content):
338343
)
339344
namespaces = {"r": ns}
340345

341-
xlsx_header = u"<wrapper {0}>".format(
346+
xlsx_header = "<wrapper {0}>".format(
342347
" ".join('xmlns:{0}="{1}"'.format(k, v) for k, v in namespaces.items())
343348
).encode("utf-8")
344-
xlsx_footer = u"</wrapper>".encode("utf-8")
349+
xlsx_footer = "</wrapper>".encode("utf-8")
345350
sheets = SHEET_FMT_MATCHER.findall(book_content)
346351
for sheet in sheets:
347352
block = xlsx_header + sheet + xlsx_footer

test.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
pip freeze
2-
nosetests --with-coverage --cover-package pyexcel_xlsxr --cover-package tests tests --with-doctest --doctest-extension=.rst README.rst pyexcel_xlsxr
2+
coverage run -m --source=pyexcel_xlsxr pytest && coverage report --show-missing

test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#/bin/bash
22
pip freeze
3-
nosetests --with-coverage --cover-package pyexcel_xlsxr --cover-package tests tests --with-doctest --doctest-extension=.rst README.rst pyexcel_xlsxr
3+
coverage run -m --source=pyexcel_xlsxr pytest && coverage report --show-missing

tests/base.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
import os # noqa
2-
import datetime # noqa
3-
41
import pyexcel
52

6-
from nose.tools import eq_, raises # noqa
7-
83

94
def create_sample_file1(file):
105
data = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", 1.1, 1]

0 commit comments

Comments
 (0)