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: ( text )

    def Create_Analysis _Page(Name,Job, Phone,Month,Ana lysing_Dict,pre view=False):
    xlApp = Dispatch ("Excel.Applica tion")
    xlWb = xlApp.Workbooks .Open ("C:\\Python25\ \Misthos.xlsx")
    xlSht = xlWb.Worksheets (1)

    xlSht.Cells(1,2 ).Value=str(Nam e)
    xlSht.Cells(2,2 ).Value=str(Job )
    xlSht.Cells(3,2 ).Value=int(Pho ne)
    xlSht.Cells(5,2 ).Value=str(Mon th)

    try:
    for i in range (9,40):
    xlSht.Cells(i,2 ).Value=Analysi ng_Dict[i-8][0]
    xlSht.Cells(i,3 ).Value=Analysi ng_Dict[i-8][1]
    xlSht.Cells(i,4 ).Value=Analysi ng_Dict[i-8][2]
    except:
    pass

    xlSht.Cells(41, 4).Value=Analys ing_Dict["Totals"][0]
    xlSht.Cells(42, 4).Value=Analys ing_Dict["Totals"][1]
    xlSht.Cells(43, 4).Value=Analys ing_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?


    Thank you in advance!!!

    Elias
  • ubentook
    New Member
    • Dec 2007
    • 58

    #2
    xlWb.Close SaveChanges:=Fa lse

    Originally posted by Elias Alhanatis
    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: ( text )

    def Create_Analysis _Page(Name,Job, Phone,Month,Ana lysing_Dict,pre view=False):
    xlApp = Dispatch ("Excel.Applica tion")
    xlWb = xlApp.Workbooks .Open ("C:\\Python25\ \Misthos.xlsx")
    xlSht = xlWb.Worksheets (1)

    xlSht.Cells(1,2 ).Value=str(Nam e)
    xlSht.Cells(2,2 ).Value=str(Job )
    xlSht.Cells(3,2 ).Value=int(Pho ne)
    xlSht.Cells(5,2 ).Value=str(Mon th)

    try:
    for i in range (9,40):
    xlSht.Cells(i,2 ).Value=Analysi ng_Dict[i-8][0]
    xlSht.Cells(i,3 ).Value=Analysi ng_Dict[i-8][1]
    xlSht.Cells(i,4 ).Value=Analysi ng_Dict[i-8][2]
    except:
    pass

    xlSht.Cells(41, 4).Value=Analys ing_Dict["Totals"][0]
    xlSht.Cells(42, 4).Value=Analys ing_Dict["Totals"][1]
    xlSht.Cells(43, 4).Value=Analys ing_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?
    Thank you in advance!!!

    Elias

    Comment

    • Elias Alhanatis
      New Member
      • Aug 2007
      • 56

      #3
      Thanks a lot friend!!!!
      Short , and to the point!!!!

      Elias

      Comment

      • dittytwo
        New Member
        • Jan 2008
        • 10

        #4
        Hi there

        I want the opposite
        and i am having a blonde day

        i can't save it
        Excel.Saved = 1 obviously only works if you have opened the document
        however for the life of me today i can't figure out how to save it once i have created it as it pops up a save dialogue box

        cheers
        D2

        Comment

        • dittytwo
          New Member
          • Jan 2008
          • 10

          #5
          Originally posted by dittytwo
          Hi there

          I want the opposite
          and i am having a blonde day

          i can't save it
          Excel.Saved = 1 obviously only works if you have opened the document
          however for the life of me today i can't figure out how to save it once i have created it as it pops up a save dialogue box

          cheers
          D2
          total blonde moment
          com_objectName. SaveAs(Filename )

          oh dear...

          D2

          Comment

          Working...