0

complex value to excel ---use excelpy

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 )?

YI-WEI's avatar
29
YI-WEI
asked 2018-04-26 03:06:43 -0500, updated 2018-04-26 03:18:36 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

2 Answers

0

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))
perolofl's avatar
3.8k
perolofl
answered 2018-04-27 17:33:03 -0500, updated 2018-04-27 17:35:41 -0500
edit flag offensive 0 remove flag delete link

Comments

thanks your advice!

YI-WEI's avatar YI-WEI (2018-04-28 08:49:04 -0500) edit
add a comment see more comments
0

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

jfconroy's avatar
186
jfconroy
answered 2018-04-27 01:49:04 -0500, updated 2018-04-27 11:37:24 -0500
edit flag offensive 0 remove flag delete 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's avatar YI-WEI (2018-04-27 08:54:55 -0500) edit
add a comment see more comments

Your Answer

Login/Signup to Answer