• python读写excel


    import xlrd
    import trans
    from xlutils.copy import copy
    
    
    def readExcel():
        rea = xlrd.open_workbook('union_group.xls', formatting_info=True)
        print(rea)
        she = rea.sheets()[0]
        nrows = she.nrows
        print('表格总行数', nrows)
        for key in range(1, nrows):
            row3_values = she.row_values(key)
            print(row3_values)
            trans_res = trans.translation("zh", row3_values[0])
            if trans_res["code"] == 0:
                translation = trans_res["translation"]
            else:
                translation = ""
            print(key)
            aa = writeExcle(key, 1, translation)
    
            print(aa)
            # break
    
    def writeExcle(row, col, translation):
        rb = xlrd.open_workbook('union_group.xls', formatting_info=True)
        # r_sheet = rb.sheet_by_index(0)
        wb = copy(rb)
        sheet = wb.get_sheet(0)
        sheet.write(row, col, translation)
        wb.save('union_group.xls')
        return "成功"
    
    
    if __name__ == '__main__':
        readExcel()
    trans是用来做翻译的,不许要的话可以注销
  • 相关阅读:
    第十一周作业
    第十周作业
    第九周作业
    第八周作业
    第九周
    第八周
    第七周
    第六周
    第五周
    实验报告二
  • 原文地址:https://www.cnblogs.com/lxz123/p/15637432.html
Copyright © 2020-2023  润新知