How to export data into Excel

Page 1 of 1

2 Replies - 493 Views - Last Post: 06 June 2015 - 11:21 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=376926&amp;s=1c9741b260750319d23f0209b1331638&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 Ripery

Reputation: 0
• Posts: 1
• Joined: 13-October 14

How to export data into Excel

Posted 04 June 2015 - 10:29 AM

Hello guys . Can someone help me out with this Python code . I want to export the x[i][k] values into excel with matrix form. For example x11=0 , x12=1, x13=0 x14=0
x21=0 , x22=0, x23=1 x24=0
And so on (I have attached my matrix figure)
```def _build_problem(self):
'''
builds the problem from provided data,
i.e. adds constraints, defines obj func. etc.
'''
if self.modelBuild:
return
self.modelBuild = True
x = {}
x[i] = {}
for k in self.workstationList:
x[i][k] = LpVariable('x_'+i+','+k, 0, 1, LpBinary)
t = LpVariable('T', None, None, LpContinuous)
taskAssignment = lpSum(x[i][k] for k in self.workstationList)
for k in self.workstationList:
if i in self.pred:
for h in self.pred[i]:
for k in self.workstationList:
precedenceC = lpSum(x[h][str(j)] for j in range(1,int(k)+1))
precedenceC = precedenceC - x[i][k]
```

Is This A Good Question/Topic? 0

Replies To: How to export data into Excel

#2 DblAAssassin

• D.I.C Regular

Reputation: 40
• Posts: 304
• Joined: 11-May 13

Re: How to export data into Excel

Posted 06 June 2015 - 11:07 AM

I was doing some reading on the topic, and people were suggesting to export to a .csv file. Others recommend to export to a DataFrame. There are also many modules that can help... https://github.com/python-excel.

Hope I was a help.

I wasn't sure if you needed help with the code or help with how to do it. If you could clarify that would be great.

#3 jon.kiparsky

• Pancakes!

Reputation: 9537
• Posts: 16,482
• Joined: 19-March 11

Re: How to export data into Excel

Posted 06 June 2015 - 11:21 AM

If you just need the data, it's almost always easier to just spit out a csv.
Check the documentation for the csv module for details, it's pretty straightforward to use.

If you want to modify a full-bore excel document, with embedded functions and such - well, excel is a notoriously befuckled mess, and its maintainers are not known for their commitment to openness, or for their attention to preserving stability over time, or for their attention to backwards compatibility, so it's probably a lot more trouble than it's worth. Libraries for dealing with excel tend to be errorful and out of date. Good luck!