Resolver Hacks contains information and code for doing fun and useful things with Resolver One. This site is created and maintained by Michael Foord, not by Resolver Systems. Please read the disclaimer before using any of the code on this site.
Accessing Files with __file__
It is common for a spreadsheet to need to access external files. For example, you can put commonly used code into Python files in the same directory as your spreadsheet and import them.
You may also want to access access other files; like image files to display in image worksheets, or data to parse and use in your spreadsheet.
Just like normal Python, user code has the __file__ variable available to it. Rather than pointing to a Python file, it contains the full path to the current spreadsheet (the '.rsl' file).
Warning
If the current spreadsheet hasn't yet been saved, __file__ will be set to None.
The following code uses __file__ to read test.txt from the same directory as the current spreadsheet file.
if __file__ is None:
raise Exception('Save the Spreadsheet!')
spreadsheetDirectory = Path.GetDirectoryName(__file__)
filePath = Path.Combine(spreadsheetDirectory, 'test.txt')
handle = open(filepath)
data = handle.read()
handle.close()
The Python Cookbook has some uesful information on Working with File Paths using .NET classes. Alternatively you can use the os.path module from the Python standard library.
Last edited Sat Jun 09 23:52:02 2007.

IronPython in Action