作者:乔山办公网日期:
返回目录:excel表格制作
from xlwt import Workbook import xlwt book = Workbook() sheet1 = book.add_sheet('Sheet 1') book.add_sheet('Sheet 2') st = xlwt.easyxf('pattern: pattern solid;') for i in range(0, 100): st = xlwt.easyxf('pattern: pattern solid;'...
see: http://nullege.com/codes/search/openpyxl.style.Color
example:
import openpyxl
from openpyxl.style import Color, Fill
from openpyxl.cell import get_column_letter
..
cell = sheet.cell(column=pt[0], row=pt[1])
cell.style.fill.fill_type = Fill.FILL_SOLID
cell.style.fill.start_color = Color(color)
cell.style.fill.end_color = Color(color)
borders = xlwt.Borders()
borders.left = 1
borders.right = 1
borders.top = 1
borders.bottom = 1
borders.bottom_colour=0x3A
style = xlwt.XFStyle()
style.borders = borders
sheet.write(0, 0, 'Firstname',style)
#Win32#打开EXCEL
WinApp = win32com.client.DispatchEx('Excel.Application')
#要处理的excel文件路径#out.file是文件 绝对路径
WinBook = WinApp.Workbooks.Open(out_file)
#要处理的excel页
WinSheet = WinBook.Worksheets('Sheet1')
#单元格添加颜色7a64e4b893e5b19e332
WinSheet.Cells(1, 1).Interior.ColorIndex = 3
#或者Range("A1")
WinSheet.Range("A1").Interior.ColorIndex = 3
#3=红色,不同的值代表不同的颜色,可以去查看msdn vba 文档,这就不详细说了
#再是RGB调色方式#Cells 和 Range都可以,Range可以选择一大片区域
WinSheet.Cells(1, 1).Interior.Color = RGB(0, 0, 255)
#或
WinSheet.Range("A1").Interior.Color = RGB(255, 0, 255)
#字体的颜色也是一样
WinSheet.Cells(1, 1).Font.ColorIndex = 3
WinSheet.Cells(1, 1).Font.Color = RGB(0, 0, 255)