TransWikia.com

Using special characters ($, % etc.) in PythonTeX

TeX - LaTeX Asked by Scott Crawshaw on December 16, 2020

I am writing a LaTeX document that retrieves values from defined ranges in a spreadsheet.

I have a Python function that I know works (it works in VS Code).

documentclass{article}
usepackage{pythontex}
begin{document}

begin{pycode}
import openpyxl
file = 'myfile.xlsx'
wb = openpyxl.load_workbook(file, data_only = True)

def excelValue(definedName):
    address = list(wb.defined_names[definedName].destinations

    for sheetname, cellAddress in address:
        cellAddress = cellAddress.replace('$', '')
    worksheet = wb[sheetname]
    return worksheet[cellAddress].value
end{pycode}

The issue is in the line cellAddress.replace('$', ' '), where LaTeX doesn’t like the $ symbol.

Any suggestions?

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP