Re: [問題] Print matrix formatting problem
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)
推
10/01 11:34, , 1F
10/01 11:34, 1F
討論串 (同標題文章)
完整討論串 (本文為第 3 之 3 篇):
Python 近期熱門文章
PTT數位生活區 即時熱門文章