python 導出excel 單元格式顏色,字體等


# import xlwt
# # 創建一個workbook 設置編碼
# workbook = xlwt.Workbook(encoding='ascii') # print(workbook) %結果%<xlwt.Workbook.Workbook object at 0x005F4630>
# # 創建一個worksheet
# worksheet = workbook.add_sheet('小馬過河')
# pattern = xlwt.Pattern() # 創建模式對象Create the Pattern
# pattern.pattern = xlwt.Pattern.SOLID_PATTERN # May be: NO_PATTERN, SOLID_PATTERN, or 0x00 through 0x12
# pattern.pattern_fore_colour = 2 # 設置模式顏色 May be: 8 through 63. 0 = Black, 1 = White, 2 = Red, 3 = Green, 4 = Blue, 5 = Yellow, 6 = Magenta, 7 = Cyan, 16 = Maroon, 17 = Dark Green, 18 = Dark Blue, 19 = Dark Yellow , almost brown), 20 = Dark Magenta, 21 = Teal, 22 = Light Gray, 23 = Dark Gray, the list goes on...
# style = xlwt.XFStyle() # 創建樣式對象Create the Pattern
# style.pattern = pattern # 將模式加入到樣式對象Add Pattern to Style
#
# font = xlwt.Font() # 為樣式創建字體
# font.name = 'Times New Roman'
# font.bold = True # 黑體
# font.underline = True # 下划線
# font.italic = True # 斜體字
# font.colour_index = 1
# style.font = font # 設定樣式
#
# worksheet.write(0, 0, '單元格內容', style) # 向單元格寫入內容時使用樣式對象style
#
# # 保存
# workbook.save('測試.xls')


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM