Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to load an excel file in IronPython?

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 ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading