Ask Your Question
0

complex value to excel ---use excelpy

asked 2018-04-26 03:06:43 -0500

YI-WEI gravatar image

updated 2018-04-26 03:18:36 -0500

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

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2018-04-27 17:33:03 -0500

perolofl gravatar image

updated 2018-04-27 17:35:41 -0500

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))
edit flag offensive delete link more

Comments

thanks your advice!

YI-WEI gravatar imageYI-WEI ( 2018-04-28 08:49:04 -0500 )edit
0

answered 2018-04-27 01:49:04 -0500

jfconroy gravatar image

updated 2018-04-27 11:37:24 -0500

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

edit flag offensive delete link more

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 ( 2018-04-27 08:54:55 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Question Tools

1 follower

Stats

Asked: 2018-04-26 03:06:43 -0500

Seen: 675 times

Last updated: Apr 27 '18