zoukankan      html  css  js  c++  java
  • 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是用来做翻译的,不许要的话可以注销
  • 相关阅读:
    C语言I博客作业06
    C语言I博客作业05
    C语言I博客作业04
    C语言I博客作业03
    C语言I博客作业02
    第一次作业
    C语言I博客作业09
    C语言I博客作业08
    C语言I博客作业07
    C语言I博客作业06
  • 原文地址:https://www.cnblogs.com/lxz123/p/15637432.html
Copyright © 2011-2022 走看看