Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Selecting data to send to Excel - set_range

Hi! I’m newbie with python and I try to export selected bus data to Excel. I made this code base on this video from Jervis Whitley

# import os,sys
PythonPath = r'C:\Program Files\PTI\PSSE32\PSSBIN'
sys.path.append(PythonPath)
os.environ['PATH'] = (r"C:\Program Files\PTI\PSSE32\PSSBIN;"
                      + os.environ['PATH'])
import excelpy
import psspy
import redirect
redirect.psse2py()
psspy.psseinit(10000)
psspy.case(r'savnw.sav')
# Buses in service 
ierr, nbuses = psspy.abuscount(-1, 1)
# Read data from sav...
ierr, buses = psspy.abusint(-1,2,string='NUMBER')
ierr, iarea = psspy.abusint(-1,2, string='AREA')
ierr, volts = psspy.abusreal(-1,2,string='PU')
# Open and Show excel
x1 = excelpy.workbook()
x1.show()
# Write Titel on Excel
x1.set_cell('a1', 'AREA')
x1.set_cell('b1', 'Bus Number')
x1.set_cell('c1', 'Voltage [pu]')
# Send data to Excel
x1.set_range(2,'a',zip(*iarea))
x1.set_range(2,'b',zip(*buses))
x1.set_range(2,'c',zip(*volts))
# Save Workbook
x1.save('demo.xlsx')

Thas work fine but when I try to send for example ONLY the data from Area 5 I can’t!. It’s a possibility in Pyhton to do a of this data? A code like:

for jj in range (0,nbuses):
    if iarea[jj]==5:
        x1.set_range(2,'a',zip(*iarea(jj)))
        x1.set_range(2,'b',zip(*buses(jj)))
        x1.set_range(2,'c',zip(*volts(jj)))

doesn’t work. Thanks a lot in advance!