How to load an excel file in IronPython?

Question:

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:UsersantoiDesktoprimo_reportae-project-reportingcodes_02_heat_recoverydataunit_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 ?

Asked By: Checster

||

Answers:

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")
Answered By: Forague