I have the following function that constructs and returns a string (used to create a formula for Excel).
def create_hyperlink_formula(target_sheet,link_text):
a = """=HYPERLINK("#'{target_sheet}'!$A$1),"{link_text}")""".format(target_sheet=target_sheet,
link_text = link_text)
return a
So by running:
create_hyperlink_formula(target_sheet = "Cover", link_text = "Return to cover page")
My desired result is as follows:
=HYPERLINK("#'Cover'!$A$1),"Return to cover page")
But instead I get this:
=HYPERLINK("#\'Cover\'!$A$1),"Return to cover page")
I cannot seem to get rid of the unwanted backslashes ("\") in this string.
I am completely lost as to why that happens and how to fix that. Even a workaround would help me a lot at this point, as string.replace() method doesn't help here either.
Many thanks in advance.