1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#Win32#打开EXCEL
WinApp = win32com.client.DispatchEx('Excel.Application')
#要处理的excel文件路径#out.file是文件 绝对路径
WinBook = WinApp.Workbooks.Open(out_file)
#要处理的excel页
WinSheet = WinBook.Worksheets('Sheet1')
#单元格添加颜色
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)
Life is short, I use python.
#Win32#打开EXCEL
WinApp = win32com.client.DispatchEx('Excel.Application')
#要处理的excel文件路径#out.file是文件 绝对路径
WinBook = WinApp.Workbooks.Open(out_file)
#要处理的excel页
WinSheet = WinBook.Worksheets('Sheet1')
#单元格添加颜色
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)