作者suzuke (suzuke)
看板Python
标题Re: [问题] Print matrix formatting problem
时间Thu Sep 29 23:56:30 2011
import win32com.client
Excel = win32com.client.Dispatch("Excel.Application")
# 显示Excel (default=0)
Excel.Visible = 1
workbook = Excel.workbooks.Add()
# 建立工作表
sheet = workbook.Sheets.Add()
# 给定工作表名称
sheet.Name = "xxxxx"
# 填入值(这边我只是大概举个例子, 可能没办法work,
主要可以用sheet.Cells(i,j).Values来填值)
for i in xrange(len(your_list)):
for j in xrange(len(your_list[i])):
sheet.Cells(i+1,j+1).Values = your_list[i][j]
# save
workbook.SaveAs("xxxx.xls")
Excel.Quit()
※ 引述《mark038 (Mark)》之铭言:
: I can't type Chinese in the computer now. Sorry蔊: The following is my output if I print a matrix (I used numpy) from a generated m*n matrix.
: But I want to generate/print a tab delimited file for reading/opening excel.
: Could anybody provide a clever solution?
: Thanks!
: [[ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 0. 0. 0. 0. 0. 0.
: 0. 0. 0. 0. 0. 0. 0. 0.]
: [ 0. 1. 0. 0. 0. 1. 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
: 0. 0. 0. 0. 0. 0. 0. 1.]
: [ 0. 0. 4. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
: 0. 0. 0. 0. 0. 0. 0. 0.]
: [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 0.
: 0. 0. 0. 0. 0. 0. 0. 0.]
: [ 1. 0. 0. 0. 0. 0. 0. 1. 0. 1. 0. 0. 1. 0. 1. 0. 0. 1.
: 0. 0. 1. 1. 0. 0. 0. 0.]
: [ 0. 0. 0. 1. 0. 0. 0. 0. 1. 0. 3. 0. 0. 1. 0. 1. 0. 0.
: 1. 0. 0. 0. 1. 0. 0. 0.]
: [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
: 0. 1. 0. 0. 0. 0. 0. 0.]
: [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
: 0. 0. 0. 0. 0. 1. 0. 0.]
: [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
: 0. 0. 0. 0. 0. 0. 1. 0.]
: [ 0. 0. 0. 0. 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
: 0. 0. 0. 0. 0. 0. 0. 0.]]
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 118.233.156.14
※ 编辑: suzuke 来自: 118.233.156.14 (09/29 23:57)
1F:推 mark038:Thanks! 10/01 11:34