Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Output table to Excel file through python

Hi, am trying to use the python to output the result from psse output file to an excel file, I have already create a output file "SMIBBESSfault" which is used to read as the object to record data to excel (The channel I want to record is the frequenct and the active power, so I set the channel as 1,2,5,6 in the code).

The code I am using is as following:

import os,sys
import win32com.client
outfile = r"""SMIB_BESS_fault.out"""
psseversion = 34

 if psseversion== 34 or psseversion== 33:
   exec('import psse%s'%psseversion)
 else:
   pssepath = r"C:\Program Files (x86)\PTI\PSSE%s\PSSBIN"%psseversion
   if pssepath not in sys.path:
       sys.path.append(pssepath)

import psspy
import dyntools
import matplotlib.pyplot as plt

chnfobj = dyntools.CHNF(outfile)
short_title, chanid, chandata = chnfobj.get_data()
chnfobj.xlsout(channels=[1,2,5,6],show=False)

I am confused, because the error don't always occur, sometimes it just keep happened, sometimes it happens when running the code for a few times and without any change.

Whenever the error occur, the error message is always as following:

Exception has occurred: com_error

(-2147418111, '\xb1\xb5\xa6\xac\xaa\xcc\xa4w\xa9\xda\xb5\xb4\xb3o\xad\xd3\xa9I\xa5s\xa1C', None, None) File "C:\Users\POWER\Desktop\p\simp 3 change xsource\chanplot22.py", line 42, in <module> chnfobj.xlsout(channels=[1,2,5,6],show=False)

Will the problem relate with the version of win32com module? Because after searching for a bit, the "com_error" seems relate with this module, but I still can't solve the problem.

Any suggestion will be much appreciate! Thanks!

Link for the outfile (google drive): https://drive.google.com/file/d/1kly0MkpOShsQGYGoBAc6zQUUS18W4pNF/view?usp=drive_link