def create_hyperlink_to_ext_resource(src_cell: xw.Range, resource_link: str, friendly_nm: str): """Creates a hyperlink formula in src_cell to external resource with given friendly_nm being the text displayed. Arguments: src_cell {xw.Range} -- cell contining hyperlink resource_link {str} -- resource link friendly_nm {str} -- text to display for hyperlink """ src_cell.formula = '=HYPERLINK({}, {})'.format(resource_link, friendly_nm)
def create_hyperlink_to_other_cell(src_cell: xw.Range, dst_cell: xw.Range, friendly_nm: str): """Creates a hyperlink formula in src_cell to dst_cell with the given friendly_nm being the text displayed. Arguments: src_cell {xw.Range} -- cell which will contain the hyperlink. dst_cell {xw.Range} -- cell which the hyperlink will lead to. friendly_nm {str} -- text of hyperlink """ link_location = '"#{}"'.format( dst_cell.get_address(include_sheetname=True)) friendly_nm = '"{}"'.format(friendly_nm.replace('"', '')) src_cell.formula = '=HYPERLINK({}, {})'.format(link_location, friendly_nm)
def apply_spaced_format_to_cell(cell: xw.Range): spaced_formula: str = get_spaced_formula(cell.formula) if rng_is_array(cell): cell.formula_array = spaced_formula else: cell.formula = spaced_formula