Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0301· OpenAIAi2 WildChat-4.8M (AI2)

import xlrd import xlwt 打开excel文件,获取工作簿对象 wb = xlrd.openworkbook('normal.xlsx')…

  1. User

    import xlrd import xlwt

    打开excel文件,获取工作簿对象

    wb = xlrd.open_workbook('normal.xlsx')

    创建写入excel文件,

    workbook = xlwt.Workbook(encoding = 'utf8')

    单页写入255条 多余的分页

    worksheet = workbook.add_sheet('My Worksheet') staticNumber = -1

    获取指定的表单

    sheet3 = wb.sheet_by_name('Sheet1')

    获取A列单元格中的值内容

    titleArray = sheet3.col_values(0)[1:] colArray = sheet3.col_values(1)[1:]

  2. Assistant

    写入第一行标题

    row_num = 0 for index, title in enumerate(titleArray): worksheet.write(row_num, index, title)

    写入内容

    for colIndex, data in enumerate(colArray): staticNumber += 1 rowIndex = 1 + staticNumber // 255 # 行号 colIndex = staticNumber % 255 # 列号 worksheet.write(rowIndex, colIndex, data)

    保存文件

    workbook.save('result.xls')