zoukankan      html  css  js  c++  java
  • Python利用openpyxl库修改excel中身份证号单元格的方法

    一、安装openpyxl库

          pip install openpyxl

    二、实例

     1 import random
     2 import time
     3 import re
     4 
     5 from openpyxl import load_workbook
     6 
     7 def idcard_generator():
     8 
     9     ARR = (7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2)
    10     LAST = ('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2')
    11     t = time.localtime()[0]
    12     x = '%02d%02d%02d%04d%02d%02d%03d' % (random.randint(10, 99), random.randint(1, 99), random.randint(1, 99), random.randint(t - 80, t - 18), random.randint(1, 12), random.randint(1, 28), random.randint(1, 999))
    13     y = 0
    14     for i in range(17):
    15         y += int(x[i]) * ARR[i]
    16     IDCard = '%s%s' % (x, LAST[y % 11])
    17     # birthday = '%s-%s-%s 00:00:00' % (IDCard[6:14][0:4], IDCard[6:14][4: 6], IDCard[6:14][6:8])
    18 
    19     return IDCard
    20 
    21 
    22 wb=load_workbook(r'C:UsersadminDesktop	ztest.xlsx')
    23 
    24 sheet=wb['Sheet1']
    25 
    26 for i in range(2,4):
    27     
    28     print sheet.cell(row=i, column=2).value
    29     sheet.cell(row=i, column=2).value = idcard_generator()
    30 wb.save(r'C:UsersadminDesktop	ztest.xlsx')
  • 相关阅读:
    菜鸟快速自学java00之变量类型
    php 接口和抽象类
    java 三大特性之多态性
    设计模式
    依赖注入
    Java设计模式工厂模式
    php 设计模式之策略模式
    大数的概述
    熟悉常用的Linux操作
    GridView动态添加列
  • 原文地址:https://www.cnblogs.com/40406-jun/p/9454052.html
Copyright © 2011-2022 走看看