1

I am trying to load an excel file within an IronPython script, which is embedded within a software. I tried to do this with the following code:

import clr
clr.AddReference("Microsoft.Office.Interop.Excel")
import Microsoft.Office.Interop.Excel as Excel
excel = Excel.ApplicationClass()
excel.Visible = True
workbook = excel.Workbooks.Open("C:\Users\antoi\Desktop\rimo_report\ae-project-reporting\codes_02_heat_recovery\data\unit_data_simp_08.xlsx")

However, I get an error that the file path cannot be found. From the error, it seems it is not searching within my own computer. How could one do this ? Do I have to import other packages ?

1 Answer 1

1

if it's just a path error, try to escape your \.

\ is a character used to escape some other characters (such as quotes, new lines, etc)

So when python is reading your code and interpreting it, it is trying to understand the characters you escaped such as \U, \a ...

To avoid this problem you can try this :

workbook = excel.Workbooks.Open("C:\\Users\\antoi\\Desktop\\rimo_report\\ae-project-reporting\\codes_02_heat_recovery\\data\\unit_data_simp_08.xlsx")
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much. Do you also know how to change cell values once the files is open ? Can't find any documentation anywhere :(
I'm sorry I don't know, I just found this link which might help you, but it doesn't use the same library as you : geeksforgeeks.org/change-value-in-excel-using-python

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.