About Excel writing cases in Python

Source: Internet
Author: User

Recently in order to realize some personal ideas need to use the data obtained in Python to Excel, referring to some of the online writing tutorials. Finally, the write format that satisfies the inner needs is completed, and the writing method is shared.

First, install the OPENPYXL library for Python, which allows Python to read and write to the. Xlxs Table File

The library is typically installed using PIP install OPENPYXL

This method is mainly for a large number of data to be obtained through a For loop write method, not much to say, the following is the code case:

 fromOpenpyxlImportworkbooklist=["ASDASF|DASFSAFDA","SDWEEWEEW|GDSDADASD","Fghkjl|werqerwae"]WB=Workbook () sheet=wb.active forI, lineinchEnumerate (list):Print(i + 1, line) a= Line.split ('|')    forJ,kinchEnumerate (a):Print(j+1, K) sheet["a%d"% (i + 1)].value =k Wb.save ('newe.xlsx')

This method enables the "|" Data is stored in NEWE.XLSX as a column

Here is a case where all the string contents need to be stored:

 fromOpenpyxlImportworkbooklist=["ASDASF|DASFSAFDA","SDWEEWEEW|GDSDADASD","Fghkjl|werqerwae"]WB=Workbook () sheet=wb.active forI, lineinchEnumerate (list):Print(i + 1, line) a= Line.split ('|') sheet["a%d"% (i + 1)].value =A[0] sheet["b%d"% (i + 1)].value = a[1] Wb.save ('newe.xlsx')

The above is simple to share, hope to be useful to you

About Excel writing cases in Python

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.