您的位置:首页 > 编程语言 > Python开发

python使用xlsxwriter操作excel文件,支持格式.xlsx

2018-02-13 13:37 676 查看
参见:https://xlsxwriter.readthedocs.io/
XlsxWriter 可以操作Excel 2007+ XLSX ,可以写入文本,数字,公式、图片、超链、合并单元格、图表等等.xlsxwriter只能创建新文件,不能读或修改已有的文件。1、主要方法wb  =  xlsxwriter.Workbook('a.xlsx')ws = wb.add_worksheet('sheet0')format1 = wb.add_format()format1.set_bold(True)format2 = wb.add_format( {'bold': True, 'font_colr' : 'red' })ws.write(0,0,'Test',format1)ws.write('C1','test2',format2)#调整列宽ws.add_column('B:B',15) wb.close()2、主要格式:
CategoryDescriptionPropertyMethod Name
FontFont type
'font_name'
set_font_name()
 Font size
'font_size'
set_font_size()
 Font color
'font_color'
set_font_color()
 Bold
'bold'
set_bold()
 Italic
'italic'
set_italic()
 Underline
'underline'
set_underline()
 Strikeout
'font_strikeout'
set_font_strikeout()
 Super/Subscript
'font_script'
set_font_script()
NumberNumeric format
'num_format'
set_num_format()
ProtectionLock cells
'locked'
set_locked()
 Hide formulas
'hidden'
set_hidden()
AlignmentHorizontal align
'align'
set_align()
 Vertical align
'valign'
set_align()
 Rotation
'rotation'
set_rotation()
 Text wrap
'text_wrap'
set_text_wrap()
 Justify last
'text_justlast'
set_text_justlast()
 Center across
'center_across'
set_center_across()
 Indentation
'indent'
set_indent()
 Shrink to fit
'shrink'
set_shrink()
PatternCell pattern
'pattern'
set_pattern()
 Background color
'bg_color'
set_bg_color()
 Foreground color
'fg_color'
set_fg_color()
BorderCell border
'border'
set_border()
 Bottom border
'bottom'
set_bottom()
 Top border
'top'
set_top()
 Left border
'left'
set_left()
 Right border
'right'
set_right()
 Border color
'border_color'
set_border_color()
 Bottom color
'bottom_color'
set_bottom_color()
 Top color
'top_color'
set_top_color()
 Left color
'left_color'
set_left_color()
 Right color
'right_color'
set_right_color()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python