0

Dyntools Overwrite Excel Sheet

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

camerond12's avatar
3
camerond12
asked 2018-03-21 19:44:01 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

5 Answers

0

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'
camerond12's avatar
3
camerond12
answered 2018-03-22 02:20:05 -0500
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments
0

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

haveityourwa's avatar
25
haveityourwa
answered 2018-03-28 19:42:35 -0500
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments
0

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

Juan's avatar
21
Juan
answered 2018-08-17 13:57:12 -0500
edit flag offensive 0 remove flag delete link

Comments

check my post at "Multi-Threading using xlsout"

jconto's avatar jconto (2018-08-17 17:58:09 -0500) edit

HI, Thanks

Juan's avatar Juan (2018-08-21 09:08:04 -0500) edit

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's avatar SAE_2016 (2018-09-07 09:14:55 -0500) edit
add a comment see more comments
0

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.

drsgao's avatar
76
drsgao
answered 2019-05-10 07:51:21 -0500
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments
0

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)
jconto's avatar
2.9k
jconto
answered 2019-05-10 11:18:12 -0500
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments

Your Answer

Login/Signup to Answer