rattail.excel

Excel utilities

rattail.excel.ExcelReader

alias of ExcelReaderXLS

class rattail.excel.ExcelReaderXLS(path, sheet=0, sheet_name=None, header=0, first_data_row=None, datefmt='%Y-%m-%d', strip_fieldnames=True)[source]

Basic class for reading Excel “legacy” (.xls) files.

Uses the xlrd package to read the files.

class rattail.excel.ExcelReaderXLSX(path, header_row=1, strip_fieldnames=True, datefmt='%Y-%m-%d', **kwargs)[source]

Basic class for reading Excel 2010 (.xslx) files.

Uses the openpyxl package to read the files.

Parameters:
  • path – Path to the Excel data file.

  • header_row – 1-based row number which contains the header, with field names.

  • strip_fieldnames – If true (the default), any whitespace surrounding the field names will be stripped, i.e. after they are read from the header row. Pass False here to suppress the behavior and leave whitespace intact.

class rattail.excel.ExcelWriter(path, fields, sheet_title=None, number_formats={}, highlight_rows=True)[source]

Base class for Excel writers.

auto_filter()[source]

Add auto filters for all columns.

auto_freeze(row=2, column=1)[source]

Freeze sheet per “the usual”

auto_resize(progress=None)[source]

(Try to) Auto-resize all data columns.

create_sheet(title)[source]

Create a new sheet in the workbook, and make it active.

save(progress=None)[source]

Save the Excel workbook to file. If progress is provided, it will be used in a hacky sort of way, i.e. from 0 to 1 only since we have no way of knowing true progress for the save operation. (But it can still be nice to let user know this is the step we’re on at least.)

write_row(data, row=None, sheet=None)[source]

Write (append) a single data row to the current sheet.

Parameters:

row – The 1-based row number to which data should be written.

write_rows(rows, sheet=None, progress=None)[source]

Write (append) a sequence of data rows to the current sheet.