Using python, openpyxl will teach you how to write excel big data easily. Import large amounts of data without worry.

         In addition to the development of the program, you may have to do some performance testing yourself. For example, for an import function, you need to import a large amount of data, to what extent.

Tens of thousands or even hundreds of thousands of data.

       Imported data The first thing we think of is of course excel import data. What do we need to do with tens of thousands of data?

 

First of all, imagine that I first fill a row of data, 20 fields, ok, OK, then let's... pull down, pull it halfway, and then you will be desperate, why 30 minutes have passed and only 20,000 pieces of data.

 

Obviously, it takes time and effort, and you will find dizziness over time. Here we come to a complete code template to help you easily get all the data. One-click generation, worry-free testing.

 

Here we are using openyxl, because elwt has a limit, an error will be reported if it exceeds 65536 lines. For our test, it is really too little. Let's make it bigger.

 

#-*- coding:utf-8 -*-
#!/usr/bin/env python
"""   __author__: mc   """
import openpyxl#导入我们需要的模块。

xl=openpyxl.Workbook()
xls=xl.create_sheet(index=0)#新建一个excel,sheet表
"""通讯录"""
list1=["年龄","姓名","手机号码"]#这里是我们需要的字段,可以根据需要自行添加,删除,修改
for i in range(1,40000):#这里是我们需要的行数。比如这里是4万
    for j,value in enumerate(list1):
        if j==0 :
            xls.cell(i,1).value = str(i)#根据特殊字段进行处理,输入不同的数值。可以自行添加其他需要的字段。
        else:#其他情况或者没有特殊字段,直接使用添加列表中的值代替。
            xls.cell(i,j+1).value=value


xl.save("通讯录.xlsx")#保存我们生成的数据

 

 

At this point, we have generated the data we need. Of course, in this way, you can also process some other data to open your friends' eyes. You can make a bet with him: I can add millions of different data in this excel within 5 minutes, believe it or not? It must be emphasized that it is different.

Friend: I believe

You: No, you don’t believe it. Fortunately, if you don’t believe it, then I will prove it to you. If I win, you invite me to dinner and I will pass on the secret to you.

friend:……

After your operation, you lost after your friend, and then you shared the article with him, which made him happy.

related suggestion:

A photo of hackers may reveal your basic information

Walk the heart confession tree, let her (he) can't help but fall in love with you

Quickly create your own WeChat chat tool with zero foundation

How to develop a simple micro-channel chat robot

To learn more about fun and interesting programming, please pay attention to "learn programming together", or scan the QR code below.

Guess you like

Origin blog.csdn.net/qq_39046854/article/details/106087135