I want to be able to directly access a workbooks data in the onFileReceived event. I have a project library script that manipulates the data but the filepath must be passed manually to the function which is not ideal.
You can use the Apache POI libraries embedded into Ignition to do this. Take the event's file bytes, wrap with a ByteArrayInputStream and feed it to the POI library. You get an in-memory spreadsheet from which you can extract any arbitrary sheets and cell values (or iterate through them).
I almost always use one-liners in any kind of event to delegate to a project library script. Scattering code all over your project is a maintenance nightmare.
In case you haven't figured this out yet, project library scripts have no scope. They use the scope of the event or object that calls them.
I was actually able to achieve what I wanted with:
def import_excel_data(byte_array):
try:
# Create a BytesIO object from the byte array
bytes_io = BytesIO(byte_array)
# Load the workbook using openpyxl
workbook = openpyxl.load_workbook(bytes_io)
# Get name of all the worksheets in the workbook
worksheet_names = workbook.sheetnames
But then you have to make sure openpyxl is installed and a compatible version. And you can suffer from jython libraries poor internationalization and date/time object support. Apache POI is supplied with Ignition. Picking the POI libraries over openpyxl is the obvious right answer.
The implication being that openpyxl is not bundled with Ignition, so it must be added to Ignition's program files by the user making it a much less portable solution than using the built-in Apache POI lib.
If you update your current gateway or install a new one, openpyxl becomes a breaking point you can avoid by using Apache. I.E. it must work with Jython 2.7 or some future version and must be manually added to every gateway that needs it.