美文网首页
xlrd+xlwt读写Excel

xlrd+xlwt读写Excel

作者: 沙漠狼神 | 来源:发表于2020-02-09 18:40 被阅读0次

    xlrd+xlwt读写Excel

    读取

    import xlrd
    xlsx = xlrd.open_workbook(filename)
    sheet = xlsx.sheet_by_name(sheetname)
    sheet = xlsx.sheet_by_index(sheetindex)
    sheet.table.cell_value(row,column)
    sheet.table.cell(row,column).value
    sheet.table.row(rownum)[column].value
    

    写入

    import xlwt
    xlsx = xlrt.Workbook()
    sheet = xlsx.add_sheet(sheetname)
    text = sheet.write(row,column,"text")
    new_workbook.save(filedir)
    
    

    复制格式

    from xlutils.copy import copy
    import xlrd
    import xlwt
    
    style = xlwt.XFStyle()
    
    ##字体
    font = xlwt.Font()
    font.name = "微软雅黑"
    font.bold = True
    font.height = 18*20
    style.font = font
    
    ##边框
    borders = xlwt.Borders()
    borders.top = xlwt.Borders.THIN
    borders.bottom = xlwt.Borders.THIN
    borders.left = xlwt.Borders.THIN
    borders.right = xlwt.Borders.THIN
    style.borders = borders
    
    ##对齐
    alignment = xlwt.Alignment()
    alignment.herz = xlwt.Alignment.HERZ_CENTER
    alignment.verz = xlwt.Alignment.VERZ_CENTER
    style.alignment = alignment
    

    相关文章

      网友评论

          本文标题:xlrd+xlwt读写Excel

          本文链接:https://www.haomeiwen.com/subject/gernxhtx.html