新聞中心
python導(dǎo)出數(shù)據(jù)到excel文件的方法:

創(chuàng)新互聯(lián)建站是一家集網(wǎng)站建設(shè),呼倫貝爾企業(yè)網(wǎng)站建設(shè),呼倫貝爾品牌網(wǎng)站建設(shè),網(wǎng)站定制,呼倫貝爾網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營(yíng)銷,網(wǎng)絡(luò)優(yōu)化,呼倫貝爾網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競(jìng)爭(zhēng)力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長(zhǎng)自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。
1、調(diào)用Workbook()對(duì)象中的add_sheet()方法
wb = xlwt.Workbook()
ws = wb.add_sheet('A Test Sheet')2、通過(guò)add_sheet()方法中的write()函數(shù)將數(shù)據(jù)寫(xiě)入到excel中,然后使用save()函數(shù)保存excel文件
ws.write(0, 0, 1234.56, style0)
ws.write(1, 0, datetime.now(), style1)
ws.write(2, 0, 1)
ws.write(2, 1, 1)
ws.write(2, 2, xlwt.Formula("A3+B3"))
wb.save('example.xls')完整代碼如下:
import xlwtfrom datetime import datetime
style0 = xlwt.easyxf('font: name Times New Roman, color-index red, bold on',num_format_str='#,##0.00')
style1 = xlwt.easyxf(num_format_str='D-MMM-YY')
wb = xlwt.Workbook()
ws = wb.add_sheet('A Test Sheet')
ws.write(0, 0, 1234.56, style0)
ws.write(1, 0, datetime.now(), style1)
ws.write(2, 0, 1)
ws.write(2, 1, 1)
ws.write(2, 2, xlwt.Formula("A3+B3"))
wb.save('example.xls')程序執(zhí)行結(jié)果如下:
更多Python知識(shí),請(qǐng)關(guān)注:Python自學(xué)網(wǎng)??!
(推薦操作系統(tǒng):windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。)
網(wǎng)站名稱:創(chuàng)新互聯(lián)Python教程:python如何導(dǎo)出數(shù)據(jù)到excel文件
網(wǎng)頁(yè)URL:http://fisionsoft.com.cn/article/cdicdgh.html


咨詢
建站咨詢
