Skip to content

Commit 0c1dea4

Browse files
authored
🔨 use ISheetWriter interface (#37)
1 parent d3b57b4 commit 0c1dea4

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

pyexcel_xls/xlsr.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import xlrd
1313
from pyexcel_io.service import has_no_digits_in_float
14-
from pyexcel_io._compact import irange
1514
from pyexcel_io.plugin_api.abstract_sheet import ISheet
1615
from pyexcel_io.plugin_api.abstract_reader import IReader
1716

@@ -38,8 +37,8 @@ def __init__(self, row_low, row_high, column_low, column_high):
3837
self.value = None
3938

4039
def register_cells(self, registry):
41-
for rowx in irange(self.__rl, self.__rh):
42-
for colx in irange(self.__cl, self.__ch):
40+
for rowx in range(self.__rl, self.__rh):
41+
for colx in range(self.__cl, self.__ch):
4342
key = "%s-%s" % (rowx, colx)
4443
registry[key] = self
4544

pyexcel_xls/xlsw.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
import xlrd
1313
from xlwt import XFStyle, Workbook
14-
from pyexcel_io.sheet import SheetWriter
14+
from pyexcel_io import constants
15+
from pyexcel_io.plugin_api.abstract_sheet import ISheetWriter
1516
from pyexcel_io.plugin_api.abstract_writer import IWriter
1617

1718
DEFAULT_DATE_FORMAT = "DD/MM/YY"
@@ -20,14 +21,18 @@
2021
EMPTY_SHEET_NOT_ALLOWED = "xlwt does not support a book without any sheets"
2122

2223

23-
class XLSheetWriter(SheetWriter):
24+
class XLSheetWriter(ISheetWriter):
2425
"""
2526
xls sheet writer
2627
"""
2728

28-
def set_sheet_name(self, name):
29-
"""Create a sheet"""
30-
self._native_sheet = self._native_book.add_sheet(name)
29+
def __init__(self, xls_book, xls_sheet, sheet_name, **keywords):
30+
if sheet_name is None:
31+
sheet_name = constants.DEFAULT_SHEET_NAME
32+
self._xls_book = xls_book
33+
self._xls_sheet = xls_sheet
34+
self._keywords = keywords
35+
self._xls_sheet = self._xls_book.add_sheet(sheet_name)
3136
self.current_row = 0
3237

3338
def write_row(self, array):
@@ -60,11 +65,14 @@ def write_row(self, array):
6065
style = XFStyle()
6166
style.num_format_str = DEFAULT_TIME_FORMAT
6267
if style:
63-
self._native_sheet.write(self.current_row, i, value, style)
68+
self._xls_sheet.write(self.current_row, i, value, style)
6469
else:
65-
self._native_sheet.write(self.current_row, i, value)
70+
self._xls_sheet.write(self.current_row, i, value)
6671
self.current_row += 1
6772

73+
def close(self):
74+
pass
75+
6876

6977
class XLSWriter(IWriter):
7078
"""

0 commit comments

Comments
 (0)