Advertisement

python表格操作单元格合并(基于Pandas的数据处理与分析)

阅读量:

结果样式:

在这里插入图片描述
复制代码
    import xlwt
    
    # 创建工作簿对象
    work_book = xlwt.Workbook()
    # 创建工作表对象
    stu_sheet = work_book.add_sheet("学生信息表")
    
    #合并单元格并写入
    stu_sheet.write_merge(0, 0, 0, 2, '姓名和年龄')
    # 往表中写入内容
    stu_sheet.write(1, 0, '张飞')
    stu_sheet.write(1, 1, '18')
    stu_sheet.write(1, 2, '男')
    stu_sheet.write(2, 0, '刘备')
    stu_sheet.write(2, 1, '32')
    stu_sheet.write(2, 2, '男')
    
    # 保存表格
    work_book.save('stu.xls')
    
    
    
    
      
      

全部评论 (0)

还没有任何评论哟~