Edit page in Livemark
(2022-09-19 18:33)

Excel Format

Excel is a very popular tabular data format that usually has xlsx (newer) and xls (older) file extensions. Frictionless supports Excel files extensively.

pip install frictionless[excel]
pip install 'frictionless[excel]' # for zsh shell

Reading Data

You can read this format using Package/Resource, for example:

from pprint import pprint
from frictionless import Resource

resource = Resource(path='table.xlsx')
pprint(resource.read_rows())
[{'id': 1, 'name': 'english'}, {'id': 2, 'name': '中国人'}]

Writing Data

The same is actual for writing:

from frictionless import Resource

source = Resource(data=[['id', 'name'], [1, 'english'], [2, 'german']])
target = source.write('table-output.xlsx')
print(target)
print(target.to_view())

Configuration

There is a dialect to configure how Frictionless read and write files in this format. For example:

from frictionless import Resource, formats

resource = Resource(data=[['id', 'name'], [1, 'english'], [2, 'german']])
resource.write('table-output-sheet.xls', control=formats.ExcelControl(sheet='My Table'))

Reference

formats.ExcelControl (class)

formats.ExcelControl (class)

Excel control representation

Signature

(*, title: Optional[str] = None, description: Optional[str] = None, sheet: Union[str, int] = 1, workbook_cache: Optional[Any] = None, fill_merged_cells: bool = False, preserve_formatting: bool = False, adjust_floating_point_error: bool = False) -> None

Parameters

  • title (Optional[str])
  • description (Optional[str])
  • sheet (Union[str, int])
  • workbook_cache (Optional[Any])
  • fill_merged_cells (bool)
  • preserve_formatting (bool)
  • adjust_floating_point_error (bool)

formats.excelControl.sheet (property)

NOTE: add docs

Signature

Union[str, int]

formats.excelControl.workbook_cache (property)

NOTE: add docs

Signature

Optional[Any]

formats.excelControl.fill_merged_cells (property)

NOTE: add docs

Signature

bool

formats.excelControl.preserve_formatting (property)

NOTE: add docs

Signature

bool

formats.excelControl.adjust_floating_point_error (property)

NOTE: add docs

Signature

bool

It's a beta version of Frictionless Framework (v5). Read Frictionless Framework (v4) docs for a version that is currently installed by default by pip.