tabularxls package

Submodules

tabularxls.main module

Tool to convert a LaTeX tabular file into an Excel-file

class tabularxls.main.KeyValue(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]

Bases: Action

tabularxls.main.main(args)[source]

Wrapper allowing fib() to be called with string arguments in a CLI fashion

Instead of returning the value from fib(), it prints the result to the stdout in a nicely formatted message.

Parameters:

args (List[str]) – command line parameters as list of strings (for example ["--verbose", "42"]).

tabularxls.main.parse_args(args)[source]

Parse command line parameters

Parameters:

args (List[str]) – command line parameters as list of strings (for example ["--help"]).

Returns:

command line parameters namespace

Return type:

argparse.Namespace

tabularxls.main.run()[source]

Calls main() passing the CLI arguments extracted from sys.argv

This function can be used as entry point to create console scripts with setuptools.

tabularxls.main.setup_logging(loglevel)[source]

Setup basic logging

Parameters:

loglevel (int) – minimum loglevel for emitting messages

tabularxls.tabular_utils module

Helper functions and classes for working with tabular data

class tabularxls.tabular_utils.WorkBook(workbook)[source]

Bases: object

This class is responsible for working with Excel data :param workbook: Excel workbook object to modify

left_align_italic
Type:

workbook format or None

left_align_italic_large
Type:

workbook format or None

left_align_italic_large_ul

setup for workbook

Type:

workbook format or None

left_align_helvetica

setup for workbook

Type:

workbook format or None

left_align_helvetica_bold

setup for workbook

Type:

workbook format or None

left_align_bold

setup for workbook

Type:

workbook format or None

left_align_bold_large

setup for workbook

Type:

workbook format or None

left_align_bold_larger

setup for workbook

Type:

workbook format or None

left_align

setup for workbook

Type:

workbook format or None

left_align_large_wrap

setup for workbook

Type:

workbook format or None

left_align_large_wrap_top

setup for workbook

Type:

workbook format or None

left_align_wrap

setup for workbook

Type:

workbook format or None

left_align_large

setup for workbook

Type:

workbook format or None

right_align

setup for workbook

Type:

workbook format or None

header_format

setup for workbook

Type:

workbook format or None

title_format

setup for workbook

Type:

workbook format or None

section_heading

setup for workbook

Type:

workbook format or None

footer_format

setup for workbook

Type:

workbook format or None

add_styles()[source]

Add all the styles to this workbook

set_format(color_name)[source]

Add color codes to the workbook style

Parameters:

color_name (str) – Name of the color to add to this workbook

Returns:

Cell format with the color code definition assigned to it

Return type:

str

tabularxls.tabular_utils.clean_the_cells(cells, aliases=None)[source]

Remove all spurious latex code from cell contents

Parameters:
  • cells (list) – List of cells containing strings to be cleaned

  • aliases (dict, optional) – If aliases are passed (default None), all strings will be cleaned with the replacements defined in the aliases

Returns:

The new cell contents

Return type:

list

tabularxls.tabular_utils.find_color_name(line: str, minimal_color_length=2)[source]

Find the color name of a str

Parameters:
  • line (str) – Line in which to find the color name

  • minimal_color_length (int) – Minimum color length

Returns:

The color found int the line

Return type:

str

tabularxls.tabular_utils.get_color_code(color_name: str)[source]

Get the code belonging to a color name

Parameters:

color_name (str) – Name of the color

Returns:

Color code

Return type:

str

tabularxls.tabular_utils.get_color_names(min_color_length=2)[source]

Get the color name definitions obtained from the matplot default list

Parameters:

min_color_length (int) – minimum length of the color names

Notes

  • By default, all matlotlib colors are taken

  • In case cbsplotlib is installed, also all CBS color definitions are taken

Returns:

All the default color names

Return type:

list

tabularxls.tabular_utils.get_max_width(input_data, name, column_index=None)[source]

Determine the maximum string in an index or column of a Dataframe

Parameters:
  • input_data (DataFrame) – The dataframe to check

  • name (str) – Name of the column to check

  • column_index (int or None) – Index of the column to check

Returns:

The maximum width of this column or index

Return type:

int

tabularxls.tabular_utils.get_multicolumns(clean_cell)[source]

Get the cell contents of a multicolumn cell

Parameters:

clean_cell (str) – Cell contents of a multicolumn cell

Returns:

The contents of the first cell and the number of following multicolumn cells

Return type:

first_cell (str), n_col (int)

tabularxls.tabular_utils.get_new_command(line)[source]

Get the contents of a LaTeX newcommand definition

Parameters:

line (str) – Line potentially containing a newcommand definition

Returns:

tabularxls.tabular_utils.get_super(content)[source]

Convert normal characters to superscript codes

Parameters:

content (str) – The string for which all characters need to be converted

Returns:

New string in only superscript characters

Return type:

superscript_content (str)

tabularxls.tabular_utils.parse_tabular(input_filename: str | Path, multi_index: bool = False, search_and_replace: dict | None = None, encoding: str = 'utf-8', top_row_merge: bool = False) DataFrame[source]

Read the tabular file and convert contents to a data frame

Parameters:
  • input_filename (str or Path) – Name of the LaTeX tabular file.

  • multi_index (bool, optional) – Convert the index into a multi index based on the first 2 columns. Defaults to False.

  • search_and_replace (dict, optional) – The search and replace strings stored in a dictionary. Defaults to None.

  • encoding (str, optional) – Encoding of the input file. Defaults to “utf-8”

  • top_row_merge (bool, optional)

Returns:

The cleaned tubular data stored in a dataframe

Return type:

DataFrame

tabularxls.tabular_utils.replace_textsuper(cell)[source]

Replace LaTeX textsuperscript characters with superscript characters

Parameters:

cell (str) – Cell contents for which the textsuperscript needs to be translated into superscript

Notes

  • Superscript in LaTeX is given with the textsuperscript{} command

Returns:

Cell contents with all superscript translated into superscript characters

Return type:

new_cell (str)

tabularxls.tabular_utils.update_width(label, max_width=None)[source]

Update the width of the current max_width based on the contents of the label

Parameters:
  • label (str) – Label to check if its width a wider than max_width

  • max_width (int or None) – Current maximum width

Returns:

Maximum width encountered so far

Return type:

int

tabularxls.tabular_utils.write_data_to_sheet_multiindex(data_df: DataFrame, file_name: str | Path, sheet_name='Sheet')[source]

Write the data to Excel file with format

Args:

data_df (DataFrame): The dataframe to write to Excel file_name (str): Name of the Excel file with format sheet_name (str): Name of the sheet to write to

Module contents