Ask Your Question
2

How to name ACCC excel results

asked 2012-07-30 18:33:20 -0600

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?

edit retag flag offensive close merge delete

Comments

OK so I've largely figured this out myself.

Peter B gravatar imagePeter B ( 2012-07-30 20:02:52 -0600 )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 gravatar imagePeter B ( 2012-07-30 20:06:21 -0600 )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 gravatar imageDaniel_Hillier ( 2012-07-31 09:06:36 -0600 )edit

Hi there! We would love to see the code.

amaity gravatar imageamaity ( 2012-07-31 12:07:45 -0600 )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 gravatar imagePeter B ( 2012-07-31 20:35:27 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2012-07-31 22:08:04 -0600

Peter B gravatar image

updated 2012-08-01 02:19:07 -0600

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.

edit flag offensive delete link more

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 ( 2012-08-01 02:25:06 -0600 )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 gravatar imagePeter B ( 2012-08-01 18:18:56 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Question Tools

1 follower

Stats

Asked: 2012-07-30 18:33:20 -0600

Seen: 740 times

Last updated: Aug 01 '12