How to shut-down Excel from Python

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Elias Alhanatis
    New Member
    • Aug 2007
    • 56

    How to shut-down Excel from Python

    Hello to everybody!

    I have created an app which calculates some statistical data.
    I use the following function to get Excel to print a page with the data.

    Code:
    def Create_Analysis_Page(Name,Job,Phone,Month,Analysing_Dict,preview=False):
    
        xlApp = Dispatch ("Excel.Application")
        xlWb = xlApp.Workbooks.Open ("C:\\Python25\\Misthos.xlsx")
        xlSht = xlWb.Worksheets (1)
            
        xlSht.Cells(1,2).Value=str(Name)
        xlSht.Cells(2,2).Value=str(Job)
        xlSht.Cells(3,2).Value=int(Phone)
        xlSht.Cells(5,2).Value=str(Month)
    
        try:
            for i in range (9,40):
                xlSht.Cells(i,2).Value=Analysing_Dict[i-8][0]
                xlSht.Cells(i,3).Value=Analysing_Dict[i-8][1]
                xlSht.Cells(i,4).Value=Analysing_Dict[i-8][2]
        except:
            pass
            
        xlSht.Cells(41,4).Value=Analysing_Dict["Totals"][0]
        xlSht.Cells(42,4).Value=Analysing_Dict["Totals"][1]
        xlSht.Cells(43,4).Value=Analysing_Dict["Totals"][2]
        
        #Preview or not....
        if preview:
            xlApp.Visible=1
            
        #Print The Sheet...
        xlSht.PrintOut()
        
        xlApp.Workbooks.Close()
        
        xlApp.Quit()
    My problem is in the last few lines , because when Excel shuts down , it pops up a "Save Changes" dialog , which is never the case in my app. How can i bypass this?
    I know that's not a purely Python question , and i will post this question on the VB forum as well , but any hint from a user who's allready been there would be helpfull!!

    Thank you in advance!!!

    Elias
  • Elias Alhanatis
    New Member
    • Aug 2007
    • 56

    #2
    For all users in the future:

    The solution to the problem can be found here

    Thanks to all of you!!!

    Elias

    Comment

    Working...