Ask Your Question
0

Dyntools Overwrite Excel Sheet

asked 2018-03-21 19:44:01 -0500

camerond12 gravatar image

Hello,

I am using dyntools to output data to excel.

dyntools.CHNF.xlsout(xlsresult, channels=[], show=False, xlsfile=xlsoutput, outfile=outfile, overwritesheet = True)

This is the code I am using, I believe that overwritesheet = True should overwite sheet1 every time I run the script.

I currently need to delete the old excel sheet every time I re run my script or else the excel workbook will create new sheets of the same data, which causes the file to become huge.

What should I do?

Thanks

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2018-03-28 19:42:35 -0500

haveityourwa gravatar image

if you also have lots of sheets you could delete a folder and remake it instead of each sheet,

if os.path.exists(PathDir + r"\sheets"):
    shutil.rmtree(PathDir + r"\sheets")
    os.makedirs(PathDir + r"\sheets")

Tried this as a comment but no formatting was available. Sorry if you got spammed with notifications of me changing the comment a bunch

edit flag offensive delete link more
0

answered 2018-03-22 02:20:05 -0500

camerond12 gravatar image

I think that this overwritesheet = true option will overwrite latest sheet if it is called more than once during simulation.

In my case, I am re running the script rather than using the dyntools command more than once in the same script.

To overcome this, I check for and delete existing excel file in directory by adding the following code just before using dyntools.CHNF.xlsout(..)

if os.path.exists(xlsoutput):
   try:
      os.remove(xlsoutput)
   except WindowsError:
      print 'file is open'
edit flag offensive delete link more

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

Stats

Asked: 2018-03-21 19:44:01 -0500

Seen: 46 times

Last updated: Mar 28