#!/usr/bin/python
from win32com.client import Dispatch
import os
#打开excel app
xlApp = Dispatch('Excel.Application')
xlApp.Visible = True
#要处理的excel文件路径#out.file是文件 绝对路径
workbook = xlApp.Workbooks.Open(os.path.join(os.getcwd(), 'test1.xlsx'))
WinSheet = workbook.Worksheets('Sheet1')
#这是关键!!!!!
def rgb_to_hex(rgb):
bgr = (rgb[2], rgb[1], rgb[0])
strValue = '%02x%02x%02x' % bgr
# print(strValue)
iValue = int(strValue, 16)
return iValue
WinSheet.Cells(1, 1).Interior.Color = rgb_to_hex((255,0,0))
#以后有事问Google,百度真坑爹