2

How to name ACCC excel results

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?

Peter B's avatar
125
Peter B
asked 2012-07-30 18:33:20 -0500
edit flag offensive 0 remove flag close merge delete

Comments

OK so I've largely figured this out myself.

Peter B's avatar Peter B (2012-07-30 20:02:52 -0500) edit

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's avatar Peter B (2012-07-30 20:06:21 -0500) edit

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's avatar Daniel_Hillier (2012-07-31 09:06:36 -0500) edit

Hi there! We would love to see the code.

amaity's avatar amaity (2012-07-31 12:07:45 -0500) edit

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

Peter B's avatar Peter B (2012-07-31 20:35:27 -0500) edit
add a comment see more comments

1 Answer

1

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.

Peter B's avatar
125
Peter B
answered 2012-07-31 22:08:04 -0500
JervisW's avatar
1.3k
JervisW
updated 2012-08-01 02:19:07 -0500
edit flag offensive 0 remove flag delete link

Comments

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

JervisW's avatar JervisW (2012-08-01 02:25:06 -0500) edit

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's avatar Peter B (2012-08-01 18:18:56 -0500) edit
add a comment see more comments

Your Answer

Login/Signup to Answer