Re: [問題] Print matrix formatting problem

看板Python作者 (suzuke)時間14年前 (2011/09/29 23:56), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串3/3 (看更多)
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
Thanks!
10/01 11:34, 1F
文章代碼(AID): #1EX9KmJM (Python)
文章代碼(AID): #1EX9KmJM (Python)