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

Ask Your Question
0

complex value to excel ---use excelpy

asked Apr 26 '18

YI-WEI gravatar image

updated Apr 26 '18

HI, I'm using excelpy set complex value to excel, I got the wrong :

ierr, totalload = psspy.systot('LOAD')

I used (set_cell) before but no work, I want to write the complex value of this API into excel,how do I do this? In addition, how to do if it is an array value(another api )?

2 answers

Sort by » oldest newest most voted
0

answered Apr 27 '18

perolofl gravatar image

updated Apr 27 '18

Yes, you can do it with formula COMPLEX!

First, define a function converting the complex value to an Excel complex formula:

def complex_formula(cmplx):
    return "=complex("+str(cmplx.real)+","+str(cmplx.imag)+")"

Then use the function when writing to Excel:

wb.set_cell((1,'a'),complex_formula(totalload))
link

Comments

thanks your advice!

YI-WEI gravatar imageYI-WEI (Apr 28 '18)
0

answered Apr 27 '18

jfconroy gravatar image

updated Apr 27 '18

import excelpy

ierr, totalload = psspy.systot('LOAD')

P = totalload.real Q = totalload.imag

wb = excelpy.workbook()

wb.setcell('A1', P) wb.setcell('B1', Q)

I'm sure you can elaborate on that basic code.

You cannot export complex numbers using this set_cell function, only real numbers. That's why I am exporting P and Q into separate cells. If you try to export a complex number you get this error message.

TypeError: Objects of type 'complex' can not be converted to a COM VARIANT

link

Comments

This method I have tried, but there is no way to let P + jQ, output to the excel in one cell ?

YI-WEI gravatar imageYI-WEI (Apr 27 '18)

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: Apr 26 '18

Seen: 731 times

Last updated: Apr 27 '18