vallettea / koala

Transpose your Excel calculations into python for better performances and scaling.
GNU General Public License v3.0
147 stars 59 forks source link

TypeError: expected string or bytes-like object #237

Closed zi-l closed 5 years ago

zi-l commented 5 years ago

Info

ubuntu: 18.04
koala2: 0.0.35
Python: 3.6.8
scipy: 1.3.1
python-dateutil: 2.8.0

code Reading excel file

from koala.Spreadsheet import Spreadsheet
sp = Spreadsheet(file=str(PATH("data/TestCases.xlsx")))
print("koala: ", sp.cell_evaluate("Report!B23"))

Issue

/home/bl/PycharmProjects/intrfc/data/TestCases.xlsx
Traceback (most recent call last):
  File "/home/bl/PycharmProjects/intrfc/utils/celpy.py", line 27, in <module>
    sp = Spreadsheet(file=str(PATH("data/TestCases.xlsx")))
  File "/home/bl/PycharmProjects/intrfc/venv/lib/python3.6/site-packages/koala/Spreadsheet.py", line 59, in __init__
    self.cells = read_cells(archive, ignore_sheets, ignore_hidden)
  File "/home/bl/PycharmProjects/intrfc/venv/lib/python3.6/site-packages/koala/reader.py", line 196, in read_cells
    cell['v'] = _cast_number(child.text)
  File "/home/bl/PycharmProjects/intrfc/venv/lib/python3.6/site-packages/koala/reader.py", line 76, in _cast_number
    m = FLOAT_REGEX.search(value)
TypeError: expected string or bytes-like object

Similar issue: #130

zi-l commented 5 years ago

The cause found. I need to write some data into excel file with openpyxl, which causing this error. I have to open excel file and save it manually to make it return to normal (refer to readme). However, if use pycel instead, everything is fine.

danielsjf commented 5 years ago

@zi-l, thanks for reporting this issue. Yes indeed, this is actually a known limitation that sometimes happens. It is also mentioned in the readme: "If this step fails, ensure that your Excel file is recent and in standalone mode (open it with Excel and save, it should rewrite the file and the resulting file should be three of four times heavier)."

I will close this for now, but always feel free to open pull requests if you find a way to improve this behaviour.