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 fashionInstead of returning the value from
fib(), it prints the result to thestdoutin 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:
tabularxls.tabular_utils module
Helper functions and classes for working with tabular data
- class tabularxls.tabular_utils.WorkBook(workbook)[source]
Bases:
objectThis 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
setup for workbook
- Type:
workbook format or None
- tabularxls.tabular_utils.clean_the_cells(cells, aliases=None)[source]
Remove all spurious latex code from cell contents
- tabularxls.tabular_utils.find_color_name(line: str, minimal_color_length=2)[source]
Find the color name of a str
- tabularxls.tabular_utils.get_color_code(color_name: str)[source]
Get the code belonging to a color name
- 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:
- 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
- tabularxls.tabular_utils.get_multicolumns(clean_cell)[source]
Get the cell contents of a multicolumn cell
- 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.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
- 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