Hi to Everyone, i create a Python Script who allow me to bring some data by an .xlsx file.
I import the clr, i can read the data. I have trouble when i must close the session with the file.
If I try to open the file evrithing is fine. If I open my task manager the EXCEL.exe process is already open.
How i can close it. Because everytime i run the script it open a new process!
Here my code:
Not to hijack this thread, but is there some sort of easy general listing of the methods available for Excel? I looked around the net and found things like this:
but for example trying to find a page in there that outlines the method to assign a value to a specific cell (as in the above example) is beyond my comprehension…
Sorry guys, but I can’t fix it!
The Excel.exe process is still there! I try everything but nothing change.
Now i’m trying to kill the process opened by my script. But it is only a bad work around.
There is my code. Try that and tell me if for you is the same.
import clr
clr.AddReference("Microsoft.Office.Interop.Excel")
from Microsoft.Office.Interop import Excel
import rhinoscriptsyntax as rs
if __name__ == '__main__':
FileLocation = "path\to\my\xls\file.xls"
ExcelApp = ApplicationClass()
workbook= None
workbook = ExcelApp.Workbooks.Open(FileLocation)
workbook.Save()
workbook.Close(SaveChanges=0)
del (workbook)
ExcelApp.Quit()
del (ExcelApp)
pass
After tweaking your code a bit to run here, I saw the same thing… Then I tried playing around a bit and I found that if you use ExcelApp.Quit and not ExcelApp.Quit() then Excel quits properly…
This is a complex problem indeed, you might try ExcelApp.Dispose() as a last resort and if this doesn`t work, see here especially look at the post by VVS from Feb 4. talking about “two dots”.
Note that I have intentionally violated the “two dot” rule when creating WB variable and it still works
The catch is to put the script inside the one function and the cleanup code inside another.
First you call the script function, and then the cleanup, and it works
Placing everything inside the same function did not work for me…