|
|
|
|
|
- import xlsxwriter,xlrd
- import sys,os.path
- fname = 'zm6.xlsx'
- if not os.path.isfile(fname):
- print u'文件路径不存在'
- sys.exit()
- data = xlrd.open_workbook(fname)
- data.sheet_names()
- table = data.sheet_by_index(0)
- nrows = table.nrows
- ncols = table.ncols
- workbook = xlsxwriter.Workbook('zm6.xlsx')
- worksheet = workbook.add_worksheet()
- worksheet.set_column(0,ncols,22)
- top = workbook.add_format({'border':1,'align':'center','bg_color':'cccccc','font_size':13,'bold':True})
- green = workbook.add_format({'border':1,'align':'center','bg_color':'green','font_size':12})
- yellow = workbook.add_format({'border':1,'bg_color':'yellow','font_size':12})
- red = workbook.add_format({'border':1,'align':'center','bg_color':'red','font_size':12})
- blank = workbook.add_format({'border':1})
- for i in xrange(nrows):
- worksheet.set_row(i,22)
- for j in xrange(ncols):
- cell_value = table.cell_value(i,j,)
- if i == 0:
- format = top
- elif i == 3 or i == 6:
- format = blank
- else:
- if j == 0 or j == 2:
- format = yellow
- elif j == 1:
- format = red
- elif j == 3:
- format = green
- green.set_num_format('yyyy-mm-dd')
- worksheet.write(i,j,cell_value,format)
- format.set_align('vcenter')
- workbook.close()
|
|