参考:https://www.jianshu.com/p/fc97dd7e822c
import xlwt #导入模块
workbook = xlwt.Workbook(encoding=‘utf-8‘) worksheet = workbook.add_sheet(‘sheet1‘) #设置字体样式 font = xlwt.Font() #字体 font.name = ‘Time New Roman‘ #加粗 font.bold = True #下划线 font.underline = True #斜体 font.italic = True #创建style style = xlwt.XFStyle() style.font = font #根据样式创建workbook worksheet.write(0, 1, ‘world‘, style) workbook.save(‘students.xls‘)
import xlwt #导入模块 workbook = xlwt.Workbook(encoding=‘utf-8‘) #创建workbook 对象 worksheet = workbook.add_sheet(‘gongzuo‘) #创建工作表sheet #worksheet2 = workbook.add_sheet(‘工作‘) #创建工作表sheet #------------------------------------------------------------------- font = xlwt.Font() # 设置字体样式 font.name = ‘Time New Roman‘ # 字体 font.bold = True # 加粗 font.underline = True # 下划线 font.italic = True # 斜体 style = xlwt.XFStyle() # 创建style style.font = font #----------------------------------------------------- worksheet.write(0, 0, ‘hello‘,style) #往表中写内容,第一各参数 行,第二个参数列,第三个参数内容 worksheet.write(0, 1, ‘01中国‘,style) worksheet.write(1, 1, ‘10中国‘,style) worksheet.write(1, 0, ‘‘,style) #------------------------------------------------------------------------------- workbook.save(‘C:\\Users\\del\\Desktop\\students.xls‘) #保存表为students.xls
原文地址:https://www.cnblogs.com/xiaobaibailongma/p/12370006.html
时间: 2024-10-12 10:44:16