Python Excel 多sheet 多條資料 自訂寫入

來源:互聯網
上載者:User

標籤:lib   row   books   pip   ant   one   www.   art   def   

pip install xlwt

python excel 資料寫入操作,處理網站資料匯出以及不是太多資料的爬蟲儲存, 用處蠻多的輪子。 

(150+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=)

 1 #coding: utf-8 2 import xlwt 3 from xlwt import Workbook 4  5  6 wb = Workbook() 7 ws = wb.add_sheet(‘Product‘) 8 ws_1 = wb.add_sheet(‘Other‘) 9 10 fontSize = xlwt.easyxf(‘font:height 200, name Calibri; align: horiz center;‘)   #字型自訂11 12 row0 = [u‘名目‘,u‘連結‘,u‘備忘‘]13 row1 = [u‘name‘,u‘file‘,u‘url‘]14 15 def title_write(row,ws):16     #產生標題17     for i in range(0,len(row)):18             col = ws.col(i)19             col.width=256*1820             if i == (len(row)-1):21                 ws.col(i).width = 256*2322             ws.write(0,i,row[i],xlwt.easyxf(‘font:height 200, name Arial_Unicode_MS, colour_index black, bold on;align: horiz center;‘))23 24 title_write(row0,ws)25 title_write(row1,ws_1)26 27 data = [{‘1‘:[u‘福爾摩斯探案集‘,u‘http://www.fuermositanan.com/‘,u‘推理‘],‘2‘:[u‘The Sherlock Holmes stories‘,u‘Arthur Conan Doyle‘,u‘https://ebooks.adelaide.edu.au/d/doyle/arthur_conan/‘]}]#這裡示範寫死了,根據實際需求更改28 29 x = 130 for i in data:31     rows_0 = i[‘1‘]32     rows_1 = i[‘2‘]33     def rows_write(content,ws):34         #產生內容35         for num,rows in enumerate(content):36             rows if rows != None else ‘‘37             ws.write(x, num, rows, fontSize)38     rows_write(rows_0,ws)39     rows_write(rows_1,ws_1)40     x += 141 42 fname=‘Books.xls‘43 wb.save(fname)

 

Python Excel 多sheet 多條資料 自訂寫入

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.