diff --git a/excel2xx/__init__.py b/excel2xx/__init__.py index f99958f..347399e 100644 --- a/excel2xx/__init__.py +++ b/excel2xx/__init__.py @@ -7,7 +7,7 @@ from excel2xx import utils, fields, fieldmeta import excel2xx.exporter as exporter -VERSION = "0.11.0" +VERSION = "0.11.1" __author__ = "cupen" __email__ = "xcupen@gmail.com" @@ -101,15 +101,36 @@ def fields(self): def rows(self): skipRows = self.__excel.fieldMeta.dataRowIdx + emptyRows = [] for row in self.__sheet.get_rows(): if skipRows > 0: skipRows -= 1 # print(row) continue + if len(row) <= 0: + emptyRows+=1 + continue + + if self._isEmptyRow(row): + emptyRows.append(row) + continue + elif len(emptyRows) > 0: + raise self.throwException(f"Invalid row with empty'{emptyRows[0]}'") yield row pass + def _isEmptyRow(self, row): + _fields = self.fields() + len(_fields) + if len(row) > len(_fields): + row = row[:len(_fields)] + for cell in row: + if cell.ctype != xlrd.XL_CELL_EMPTY: + return False + pass + return True + def toList(self): return list(iter(self)) @@ -159,7 +180,6 @@ def toKV(self): def toDataFrame(self): import pandas - return pandas.DataFrame(self, columns=self.fields().keys()) @property diff --git a/excel2xx/codegen/__init__.py b/excel2xx/codegen/__init__.py index 7fa042c..c6dfc7c 100644 --- a/excel2xx/codegen/__init__.py +++ b/excel2xx/codegen/__init__.py @@ -11,7 +11,7 @@ NOTE = "// DONT EDIT: generated by excel2xx/codegen.\n" -def generate(src: list, context={}, note=NOTE): +def generate(src: list, context={}, note=NOTE, encoding="utf-8", newline="\n"): """ generate source code from mako template files """ @@ -42,7 +42,7 @@ def generate(src: list, context={}, note=NOTE): fpath_new = fpath.replace(".mako", "") try: text = tmpl.render(**ctx) - with open(fpath_new, "w", encoding="utf-8") as fp: + with open(fpath_new, "w", encoding=encoding, newline=newline) as fp: if note: fp.write(note) fp.write(text) diff --git a/setup.py b/setup.py index 581ede0..d35a793 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ setup( name="excel2xx", - version="0.11.0", + version="0.11.1", packages=find_packages(), url="https://github.com/cupen/excel2xx", license="WTFPL",