Python openpyxl.workbook.Workbook() Examples
The following are 26
code examples of openpyxl.workbook.Workbook().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
openpyxl.workbook
, or try the search function
.
Example #1
Source File: excel.py From recruit with Apache License 2.0 | 11 votes |
def __init__(self, path, engine=None, encoding=None, mode='w', **engine_kwargs): # Use the xlwt module as the Excel writer. import xlwt engine_kwargs['engine'] = engine if mode == 'a': raise ValueError('Append mode is not supported with xlwt!') super(_XlwtWriter, self).__init__(path, mode=mode, **engine_kwargs) if encoding is None: encoding = 'ascii' self.book = xlwt.Workbook(encoding=encoding) self.fm_datetime = xlwt.easyxf(num_format_str=self.datetime_format) self.fm_date = xlwt.easyxf(num_format_str=self.date_format)
Example #2
Source File: excel.py From recruit with Apache License 2.0 | 6 votes |
def __init__(self, path, engine=None, mode='w', **engine_kwargs): # Use the openpyxl module as the Excel writer. from openpyxl.workbook import Workbook super(_OpenpyxlWriter, self).__init__(path, mode=mode, **engine_kwargs) if self.mode == 'a': # Load from existing workbook from openpyxl import load_workbook book = load_workbook(self.path) self.book = book else: # Create workbook object with default optimized_write=True. self.book = Workbook() if self.book.worksheets: try: self.book.remove(self.book.worksheets[0]) except AttributeError: # compat - for openpyxl <= 2.4 self.book.remove_sheet(self.book.worksheets[0])
Example #3
Source File: excel.py From recruit with Apache License 2.0 | 6 votes |
def __init__(self, path, engine=None, date_format=None, datetime_format=None, mode='w', **engine_kwargs): # Use the xlsxwriter module as the Excel writer. import xlsxwriter if mode == 'a': raise ValueError('Append mode is not supported with xlsxwriter!') super(_XlsxWriter, self).__init__(path, engine=engine, date_format=date_format, datetime_format=datetime_format, mode=mode, **engine_kwargs) self.book = xlsxwriter.Workbook(path, **engine_kwargs)
Example #4
Source File: excel.py From elasticintel with GNU General Public License v3.0 | 6 votes |
def __init__(self, path, engine=None, **engine_kwargs): if not openpyxl_compat.is_compat(major_ver=self.openpyxl_majorver): raise ValueError('Installed openpyxl is not supported at this ' 'time. Use {majorver}.x.y.' .format(majorver=self.openpyxl_majorver)) # Use the openpyxl module as the Excel writer. from openpyxl.workbook import Workbook super(_Openpyxl1Writer, self).__init__(path, **engine_kwargs) # Create workbook object with default optimized_write=True. self.book = Workbook() # Openpyxl 1.6.1 adds a dummy sheet. We remove it. if self.book.worksheets: try: self.book.remove(self.book.worksheets[0]) except AttributeError: # compat self.book.remove_sheet(self.book.worksheets[0])
Example #5
Source File: excel.py From vnpy_crypto with MIT License | 6 votes |
def __init__(self, path, engine=None, **engine_kwargs): # Use the openpyxl module as the Excel writer. from openpyxl.workbook import Workbook super(_OpenpyxlWriter, self).__init__(path, **engine_kwargs) # Create workbook object with default optimized_write=True. self.book = Workbook() # Openpyxl 1.6.1 adds a dummy sheet. We remove it. if self.book.worksheets: try: self.book.remove(self.book.worksheets[0]) except AttributeError: # compat self.book.remove_sheet(self.book.worksheets[0])
Example #6
Source File: timeliner.py From volatility with GNU General Public License v2.0 | 6 votes |
def render_xlsx(self, outfd, data): wb = Workbook(optimized_write = True) ws = wb.create_sheet() ws.title = 'Timeline Output' header = ["Time", "Type", "Item", "Details", "Reason"] ws.append(header) total = 1 for line in data: coldata = line.split("|") ws.append(coldata) total += 1 wb.save(filename = self._config.OUTPUT_FILE) if self._config.HIGHLIGHT != None: wb = load_workbook(filename = self._config.OUTPUT_FILE) ws = wb.get_sheet_by_name(name = "Timeline Output") for col in xrange(1, len(header) + 1): ws.cell("{0}{1}".format(get_column_letter(col), 1)).style.font.bold = True for row in xrange(2, total + 1): for col in xrange(2, len(header)): if ws.cell("{0}{1}".format(get_column_letter(col), row)).value in self.suspicious.keys(): self.fill(ws, row, len(header) + 1, self.suspicious[ws.cell("{0}{1}".format(get_column_letter(col), row)).value]["color"]) ws.cell("{0}{1}".format(get_column_letter(col + 1), row)).value = self.suspicious[ws.cell("{0}{1}".format(get_column_letter(col), row)).value]["reason"] wb.save(filename = self._config.OUTPUT_FILE)
Example #7
Source File: excel.py From Splunking-Crime with GNU Affero General Public License v3.0 | 6 votes |
def __init__(self, path, engine=None, **engine_kwargs): if not openpyxl_compat.is_compat(major_ver=self.openpyxl_majorver): raise ValueError('Installed openpyxl is not supported at this ' 'time. Use {majorver}.x.y.' .format(majorver=self.openpyxl_majorver)) # Use the openpyxl module as the Excel writer. from openpyxl.workbook import Workbook super(_Openpyxl1Writer, self).__init__(path, **engine_kwargs) # Create workbook object with default optimized_write=True. self.book = Workbook() # Openpyxl 1.6.1 adds a dummy sheet. We remove it. if self.book.worksheets: try: self.book.remove(self.book.worksheets[0]) except AttributeError: # compat self.book.remove_sheet(self.book.worksheets[0])
Example #8
Source File: timeliner.py From DAMM with GNU General Public License v2.0 | 6 votes |
def render_xlsx(self, outfd, data): wb = Workbook(optimized_write = True) ws = wb.create_sheet() ws.title = 'Timeline Output' header = ["Time", "Type", "Item", "Details", "Reason"] ws.append(header) total = 1 for line in data: coldata = line.split("|") ws.append(coldata) total += 1 wb.save(filename = self._config.OUTPUT_FILE) if self._config.HIGHLIGHT != None: wb = load_workbook(filename = self._config.OUTPUT_FILE) ws = wb.get_sheet_by_name(name = "Timeline Output") for col in xrange(1, len(header) + 1): ws.cell("{0}{1}".format(get_column_letter(col), 1)).style.font.bold = True for row in xrange(2, total + 1): for col in xrange(2, len(header)): if ws.cell("{0}{1}".format(get_column_letter(col), row)).value in self.suspicious.keys(): self.fill(ws, row, len(header) + 1, self.suspicious[ws.cell("{0}{1}".format(get_column_letter(col), row)).value]["color"]) ws.cell("{0}{1}".format(get_column_letter(col + 1), row)).value = self.suspicious[ws.cell("{0}{1}".format(get_column_letter(col), row)).value]["reason"] wb.save(filename = self._config.OUTPUT_FILE)
Example #9
Source File: excel.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def __init__(self, path, engine=None, mode='w', **engine_kwargs): # Use the openpyxl module as the Excel writer. from openpyxl.workbook import Workbook super(_OpenpyxlWriter, self).__init__(path, mode=mode, **engine_kwargs) if self.mode == 'a': # Load from existing workbook from openpyxl import load_workbook book = load_workbook(self.path) self.book = book else: # Create workbook object with default optimized_write=True. self.book = Workbook() if self.book.worksheets: try: self.book.remove(self.book.worksheets[0]) except AttributeError: # compat - for openpyxl <= 2.4 self.book.remove_sheet(self.book.worksheets[0])
Example #10
Source File: excel.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def __init__(self, path, engine=None, date_format=None, datetime_format=None, mode='w', **engine_kwargs): # Use the xlsxwriter module as the Excel writer. import xlsxwriter if mode == 'a': raise ValueError('Append mode is not supported with xlsxwriter!') super(_XlsxWriter, self).__init__(path, engine=engine, date_format=date_format, datetime_format=datetime_format, mode=mode, **engine_kwargs) self.book = xlsxwriter.Workbook(path, **engine_kwargs)
Example #11
Source File: excel.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def __init__(self, path, engine=None, date_format=None, datetime_format=None, **engine_kwargs): # Use the xlsxwriter module as the Excel writer. import xlsxwriter super(_XlsxWriter, self).__init__(path, engine=engine, date_format=date_format, datetime_format=datetime_format, **engine_kwargs) self.book = xlsxwriter.Workbook(path, **engine_kwargs)
Example #12
Source File: excel.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def __init__(self, path, engine=None, date_format=None, datetime_format=None, **engine_kwargs): # Use the xlsxwriter module as the Excel writer. import xlsxwriter super(_XlsxWriter, self).__init__(path, engine=engine, date_format=date_format, datetime_format=datetime_format, **engine_kwargs) self.book = xlsxwriter.Workbook(path, **engine_kwargs)
Example #13
Source File: xlsx.py From vortessence with GNU General Public License v2.0 | 5 votes |
def __init__(self, renderers_func, config): if not has_openpyxl: debug.error("You must install OpenPyxl 2.1.2 for xlsx format:\n\thttps://pypi.python.org/pypi/openpyxl") self._config = config self._columns = None self._text_cell_renderers_func = renderers_func self._text_cell_renderers = None self._wb = Workbook(optimized_write = True) self._ws = self._wb.create_sheet()
Example #14
Source File: xlsx.py From volatility with GNU General Public License v2.0 | 5 votes |
def __init__(self, renderers_func, config): if not has_openpyxl: debug.error("You must install OpenPyxl 2.1.2 for xlsx format:\n\thttps://pypi.python.org/pypi/openpyxl") self._config = config self._columns = None self._text_cell_renderers_func = renderers_func self._text_cell_renderers = None self._wb = Workbook(optimized_write = True) self._ws = self._wb.create_sheet()
Example #15
Source File: excelform.py From spider with Apache License 2.0 | 5 votes |
def __init__(self, ws_naem, excel_name): self.wb = Workbook() self.ws_naem = self.wb.active self.excel_name = excel_name
Example #16
Source File: excel.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def __init__(self, path, engine=None, encoding=None, mode='w', **engine_kwargs): # Use the xlwt module as the Excel writer. import xlwt engine_kwargs['engine'] = engine if mode == 'a': raise ValueError('Append mode is not supported with xlwt!') super(_XlwtWriter, self).__init__(path, mode=mode, **engine_kwargs) if encoding is None: encoding = 'ascii' self.book = xlwt.Workbook(encoding=encoding) self.fm_datetime = xlwt.easyxf(num_format_str=self.datetime_format) self.fm_date = xlwt.easyxf(num_format_str=self.date_format)
Example #17
Source File: excel.py From Computable with MIT License | 5 votes |
def __init__(self, path, engine=None, date_format=None, datetime_format=None, **engine_kwargs): # Use the xlsxwriter module as the Excel writer. import xlsxwriter super(_XlsxWriter, self).__init__(path, engine=engine, date_format=date_format, datetime_format=datetime_format, **engine_kwargs) self.book = xlsxwriter.Workbook(path, **engine_kwargs)
Example #18
Source File: excel.py From Computable with MIT License | 5 votes |
def __init__(self, path, engine=None, **engine_kwargs): # Use the openpyxl module as the Excel writer. from openpyxl.workbook import Workbook super(_OpenpyxlWriter, self).__init__(path, **engine_kwargs) # Create workbook object with default optimized_write=True. self.book = Workbook() # Openpyxl 1.6.1 adds a dummy sheet. We remove it. if self.book.worksheets: self.book.remove_sheet(self.book.worksheets[0])
Example #19
Source File: excel.py From vnpy_crypto with MIT License | 5 votes |
def __init__(self, path, engine=None, date_format=None, datetime_format=None, **engine_kwargs): # Use the xlsxwriter module as the Excel writer. import xlsxwriter super(_XlsxWriter, self).__init__(path, engine=engine, date_format=date_format, datetime_format=datetime_format, **engine_kwargs) self.book = xlsxwriter.Workbook(path, **engine_kwargs)
Example #20
Source File: xlsx.py From aumfor with GNU General Public License v3.0 | 5 votes |
def __init__(self, renderers_func, config): if not has_openpyxl: debug.error("You must install OpenPyxl 2.1.2 for xlsx format:\n\thttps://pypi.python.org/pypi/openpyxl") self._config = config self._columns = None self._text_cell_renderers_func = renderers_func self._text_cell_renderers = None self._wb = Workbook(optimized_write = True) self._ws = self._wb.create_sheet()
Example #21
Source File: excel.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 4 votes |
def __init__(self, filepath_or_buffer): """Reader using xlrd engine. Parameters ---------- filepath_or_buffer : string, path object or Workbook Object to be parsed. """ err_msg = "Install xlrd >= 1.0.0 for Excel support" try: import xlrd except ImportError: raise ImportError(err_msg) else: if xlrd.__VERSION__ < LooseVersion("1.0.0"): raise ImportError(err_msg + ". Current version " + xlrd.__VERSION__) # If filepath_or_buffer is a url, want to keep the data as bytes so # can't pass to get_filepath_or_buffer() if _is_url(filepath_or_buffer): filepath_or_buffer = _urlopen(filepath_or_buffer) elif not isinstance(filepath_or_buffer, (ExcelFile, xlrd.Book)): filepath_or_buffer, _, _, _ = get_filepath_or_buffer( filepath_or_buffer) if isinstance(filepath_or_buffer, xlrd.Book): self.book = filepath_or_buffer elif not isinstance(filepath_or_buffer, xlrd.Book) and hasattr( filepath_or_buffer, "read"): # N.B. xlrd.Book has a read attribute too if hasattr(filepath_or_buffer, 'seek'): try: # GH 19779 filepath_or_buffer.seek(0) except UnsupportedOperation: # HTTPResponse does not support seek() # GH 20434 pass data = filepath_or_buffer.read() self.book = xlrd.open_workbook(file_contents=data) elif isinstance(filepath_or_buffer, compat.string_types): self.book = xlrd.open_workbook(filepath_or_buffer) else: raise ValueError('Must explicitly set engine if not passing in' ' buffer or path for io.')
Example #22
Source File: excel.py From Computable with MIT License | 4 votes |
def __init__(self, path, engine=None, **engine_kwargs): # Use the xlwt module as the Excel writer. import xlwt super(_XlwtWriter, self).__init__(path, **engine_kwargs) self.book = xlwt.Workbook() self.fm_datetime = xlwt.easyxf(num_format_str=self.datetime_format) self.fm_date = xlwt.easyxf(num_format_str=self.date_format)
Example #23
Source File: excel.py From Splunking-Crime with GNU Affero General Public License v3.0 | 4 votes |
def __init__(self, path, engine=None, encoding=None, **engine_kwargs): # Use the xlwt module as the Excel writer. import xlwt engine_kwargs['engine'] = engine super(_XlwtWriter, self).__init__(path, **engine_kwargs) if encoding is None: encoding = 'ascii' self.book = xlwt.Workbook(encoding=encoding) self.fm_datetime = xlwt.easyxf(num_format_str=self.datetime_format) self.fm_date = xlwt.easyxf(num_format_str=self.date_format)
Example #24
Source File: excel.py From vnpy_crypto with MIT License | 4 votes |
def __init__(self, path, engine=None, encoding=None, **engine_kwargs): # Use the xlwt module as the Excel writer. import xlwt engine_kwargs['engine'] = engine super(_XlwtWriter, self).__init__(path, **engine_kwargs) if encoding is None: encoding = 'ascii' self.book = xlwt.Workbook(encoding=encoding) self.fm_datetime = xlwt.easyxf(num_format_str=self.datetime_format) self.fm_date = xlwt.easyxf(num_format_str=self.date_format)
Example #25
Source File: excel.py From elasticintel with GNU General Public License v3.0 | 4 votes |
def __init__(self, path, engine=None, encoding=None, **engine_kwargs): # Use the xlwt module as the Excel writer. import xlwt engine_kwargs['engine'] = engine super(_XlwtWriter, self).__init__(path, **engine_kwargs) if encoding is None: encoding = 'ascii' self.book = xlwt.Workbook(encoding=encoding) self.fm_datetime = xlwt.easyxf(num_format_str=self.datetime_format) self.fm_date = xlwt.easyxf(num_format_str=self.date_format)
Example #26
Source File: excel.py From recruit with Apache License 2.0 | 4 votes |
def __init__(self, filepath_or_buffer): """Reader using xlrd engine. Parameters ---------- filepath_or_buffer : string, path object or Workbook Object to be parsed. """ err_msg = "Install xlrd >= 1.0.0 for Excel support" try: import xlrd except ImportError: raise ImportError(err_msg) else: if xlrd.__VERSION__ < LooseVersion("1.0.0"): raise ImportError(err_msg + ". Current version " + xlrd.__VERSION__) # If filepath_or_buffer is a url, want to keep the data as bytes so # can't pass to get_filepath_or_buffer() if _is_url(filepath_or_buffer): filepath_or_buffer = _urlopen(filepath_or_buffer) elif not isinstance(filepath_or_buffer, (ExcelFile, xlrd.Book)): filepath_or_buffer, _, _, _ = get_filepath_or_buffer( filepath_or_buffer) if isinstance(filepath_or_buffer, xlrd.Book): self.book = filepath_or_buffer elif not isinstance(filepath_or_buffer, xlrd.Book) and hasattr( filepath_or_buffer, "read"): # N.B. xlrd.Book has a read attribute too if hasattr(filepath_or_buffer, 'seek'): try: # GH 19779 filepath_or_buffer.seek(0) except UnsupportedOperation: # HTTPResponse does not support seek() # GH 20434 pass data = filepath_or_buffer.read() self.book = xlrd.open_workbook(file_contents=data) elif isinstance(filepath_or_buffer, compat.string_types): self.book = xlrd.open_workbook(filepath_or_buffer) else: raise ValueError('Must explicitly set engine if not passing in' ' buffer or path for io.')