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

Ask Your Question
0

Dyntools Overwrite Excel Sheet

asked Mar 22 '18

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

5 answers

Sort by » oldest newest most voted
0

answered May 10 '19

jconto gravatar image

In v.33.12, the overwritesheet setting works as expected. The following is the code I used:

   try: 
     chnfobj.xlsout(channels=mychannels, 
                    outfile=filei,
                    xlsfile=XLSfile,
                    sheet=sheetname,
                    overwritesheet = True,
                    show=False 
                    )
   except:
     print '\n ERROR: Exporting Channels to %s Excel file, sheet %s failed.'%(XLSfile,sheetname)
link
0

answered May 10 '19

drsgao gravatar image

I found that even if you set overwritesheet = True, it does not always overwrite it. In fact, I have encountered multiple cases where I wanted it to be overwritten but new sheets were added to the workbook instead. Could be a bug.

link
0

answered Aug 17 '18

Juan gravatar image

I have the following problem Dyntools does not extract data from file out

** LINES PER PAGE for FILE OUTPUT set to 60

Output completed Traceback (most recent call last): File "C:\0-C\0-Simulaciones\Caso\Simulación.py", line 227, in <module> datosexcel = dyntools.CHNF(archivoout + '.out') File ".\dyntools.py", line 1023, in init File ".\dyntools.py", line 351, in outextractdata File ".\dyntools.py", line 321, in outextractid

Couldn't open Python file: C:\0-C\0-Simulaciones\Caso\Simulación.py

link

Comments

check my post at "Multi-Threading using xlsout"

jconto gravatar imagejconto (Aug 17 '18)

HI, Thanks

Juan gravatar imageJuan (Aug 21 '18)

Hello, I don't know how to solve this problem, but my opinion is that you should never use orthographic accent in Python even in comments or files names.

SAE_2016 gravatar imageSAE_2016 (Sep 7 '18)
0

answered Mar 29 '18

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

link
0

answered Mar 22 '18

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'
link

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: Mar 22 '18

Seen: 916 times

Last updated: May 10 '19