First time here? We are a friendly community of Power Systems Engineers. Check out the FAQ!
1 | initial version |
An example of writing & reading excel files using excelpy follows: (change psse34 to psse33 in line 3 for PSSe v.33)
#excelpy_demo
#______________________________________________________________
import psse34
#import psse33
#______________________________________________________________
import excelpy
xlsfile = r"excelpy_test.xlsx"
testxls = excelpy.workbook(xlsfile,"test",overwritesheet=True, mode='w')
#_____________________Writing test_____________________________
testxls.show()
testxls.font_sheet()
testdata=[
['CON#', 'LABEL' , 'Max MW', 'DESCRIPTION'],
[' ', 'BASE CASE' , 756.25 , 'BASE CASE '],
['1', 'TRIP1NUCLEAR', 1000.0 , 'REMOVE UNIT 1'],
['2', 'TRIP2NUCLEAR', 0.0 , 'REMOVE UNIT 1'],
['' , '' , '' , 'REMOVE UNIT 2'],
['3', 'ADDLARGELOAD', 0.0 , 'INCREASE LOAD'],
['4', 'LOSEWESTGEN' , 625.0 , 'REMOVE UNIT 3'],
['5', 'LOSEWESTBIGT', 312.5 , 'TRIP LINE 1 '],
]
#Within a sheet, goto target cell (1,1), add title
row=1
col=1
testxls.set_cell(value="How to use EXCELPY module?",
address=(row,col),
fontName="Arial",fontSize=12,fontColor='red',fontStyle=('Bold','italic'))
row += 2 #add one blank row -> (3,1)
bottomRow, rightCol = testxls.set_range(row,col,testdata,transpose=False)
# writing is done, do some coloring & formatting
testxls.font ((row,1,row,rightCol),fontStyle='bold',fontColor='blue') #<- cell (3,1)
testxls.align((row,1,row,rightCol),alignv='h_center')
testxls.align((row,1,bottomRow,2) ,alignv='h_center')
testxls.autofit_columns((row,2,row,rightCol))
testxls.font((row,3,bottomRow,3),numberFormat='0.000')
#repeat with transpose ON
row = 2 + bottomRow
bottomRow, rightCol = testxls.set_range(row,col,testdata,transpose=True)
testxls.save(xlsfile)
print "Writing demo:"
print "Excel workbook saved to %s file.\n"% xlsfile
testxls.close()
#______________________________________________________________
#_____________________Reading test_____________________________
import excelpy
xlsfile = r"excelpy_test.xlsx"
print "Reading demo:"
print "Data read from Excel %s file.\n"% xlsfile
testxls = excelpy.workbook(xlsfile,"test",mode='r')
row=1
col=1
print testxls.get_cell((row,col))
row=3
col=1
rowe= row+3
#datalst = testxls.get_range(((row,col),(rowe,col+3)))
datalst = testxls.get_range((row,col,rowe,col+3))
for x in datalst: print x
testxls.close()