First time here? We are a friendly community of Power Systems Engineers. Check out the FAQ!

Ask Your Question
2

How to name ACCC excel results

asked Jul 31 '12

Peter B gravatar image

I see that previously a question was asked about how to automate the export of ACCC results to excel. I can manage the export part.

What I can't figure out is how to name the output excel file via a GUI that shows the directory the file is to be saved in (this is useful as a memory prompt for previously used naming conventions etc).

I've tried using

import tkFileDialog filename = tkFileDialog.askopenfilename()

and

import tkFileDialog filename = tkFileDialog.asksaveasfilename()

In various different ways without success. Any ideas?

Comments

OK so I've largely figured this out myself.

Peter B gravatar imagePeter B (Jul 31 '12)

Arrgh! I want to add a space and it keeps posting! Anyway I've largely figured this out myself. If someone can tell me how to paste code such that it looks readable and isn't jumbled in as normal txt I'll put it up. There is a bug though which I will also explain.

Peter B gravatar imagePeter B (Jul 31 '12)

For an inline code snippet, you can surround the code in backticks ( ` ). For a code block, the code needs to be indented from the normal text. You can also use the "101..." button in the editor toolbar to do this for you. Nice work btw.

Daniel_Hillier gravatar imageDaniel_Hillier (Jul 31 '12)

Hi there! We would love to see the code.

amaity gravatar imageamaity (Jul 31 '12)

import tkFileDialog, ntpath filetypes = [('Excel Workbook', '*.xlsx'),('All Files','*.*')] filenamesaveas = tkFileDialog.asksaveasfilename(filetypes=filetypes, title='Results Workbook Name') xlsfilename = ntpath.basename(filenamesaveas)

Peter B gravatar imagePeter B (Aug 1 '12)

1 answer

Sort by » oldest newest most voted
1

answered Aug 1 '12

Peter B gravatar image

updated Aug 1 '12

JervisW gravatar image

Ok I've figured it out as well as fixed the bug that plagued my earlier idea (sorry this posted code still doesn't look that good).

import Tkinter, tkFileDialog, ntpath

root = Tkinter.Tk()                               
root.withdraw()

filetypes = [('Excel Workbook', '*.xlsx'),('All Files','*.*')]

filenamesaveas = tkFileDialog.asksaveasfilename(
                              filetypes=filetypes, 
                              title='Results Workbook Name')

xlsfilename =  ntpath.basename(filenamesaveas)

The 'root = Tkinter.Tk()' etc is to stop a dummy Tkinter window coming up that crashes PSS/E if it's closed.

link

Comments

Hi Peter, does this show the correct directory when you run it, or does it always use the same default directory?

JervisW gravatar imageJervisW (Aug 1 '12)

It always shows the directory that the python script is in, which is what I was trying to do. If one wanted it to show the directory that the .sav case is in (if it isn't also in the same directory as the python script) that would take some extra tweaking.

Peter B gravatar imagePeter B (Aug 2 '12)

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.
Want to format code in your answer? Here is a one minute demo on Youtube

Add Answer

[hide preview]

Question Tools

1 follower

Stats

Asked: Jul 31 '12

Seen: 766 times

Last updated: Aug 01 '12