🔨 use ISheetWriter interface (#37)

This commit is contained in:
jaska 2020-10-02 03:26:26 +01:00 committed by GitHub
parent d3b57b434b
commit 0c1dea41bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 10 deletions

View File

@ -11,7 +11,6 @@ import datetime
import xlrd
from pyexcel_io.service import has_no_digits_in_float
from pyexcel_io._compact import irange
from pyexcel_io.plugin_api.abstract_sheet import ISheet
from pyexcel_io.plugin_api.abstract_reader import IReader
@ -38,8 +37,8 @@ class MergedCell(object):
self.value = None
def register_cells(self, registry):
for rowx in irange(self.__rl, self.__rh):
for colx in irange(self.__cl, self.__ch):
for rowx in range(self.__rl, self.__rh):
for colx in range(self.__cl, self.__ch):
key = "%s-%s" % (rowx, colx)
registry[key] = self

View File

@ -11,7 +11,8 @@ import datetime
import xlrd
from xlwt import XFStyle, Workbook
from pyexcel_io.sheet import SheetWriter
from pyexcel_io import constants
from pyexcel_io.plugin_api.abstract_sheet import ISheetWriter
from pyexcel_io.plugin_api.abstract_writer import IWriter
DEFAULT_DATE_FORMAT = "DD/MM/YY"
@ -20,14 +21,18 @@ DEFAULT_DATETIME_FORMAT = "%s %s" % (DEFAULT_DATE_FORMAT, DEFAULT_TIME_FORMAT)
EMPTY_SHEET_NOT_ALLOWED = "xlwt does not support a book without any sheets"
class XLSheetWriter(SheetWriter):
class XLSheetWriter(ISheetWriter):
"""
xls sheet writer
"""
def set_sheet_name(self, name):
"""Create a sheet"""
self._native_sheet = self._native_book.add_sheet(name)
def __init__(self, xls_book, xls_sheet, sheet_name, **keywords):
if sheet_name is None:
sheet_name = constants.DEFAULT_SHEET_NAME
self._xls_book = xls_book
self._xls_sheet = xls_sheet
self._keywords = keywords
self._xls_sheet = self._xls_book.add_sheet(sheet_name)
self.current_row = 0
def write_row(self, array):
@ -60,11 +65,14 @@ class XLSheetWriter(SheetWriter):
style = XFStyle()
style.num_format_str = DEFAULT_TIME_FORMAT
if style:
self._native_sheet.write(self.current_row, i, value, style)
self._xls_sheet.write(self.current_row, i, value, style)
else:
self._native_sheet.write(self.current_row, i, value)
self._xls_sheet.write(self.current_row, i, value)
self.current_row += 1
def close(self):
pass
class XLSWriter(IWriter):
"""