Use Python to read and write versions of Excel2007 and above, from the official demo

Source: Internet
Author: User

Daniel please skip, Novice can refer to, see the following code comments,

Another problem, want to learn this language, the best English cow some, can go to the official website to see more useful library, Chinese information is not very full

1 #Run Environment 3.4, below this action Excel package is for Excel2007 and above version of the2 #import the necessary packages before you can manipulate Excel3 #Import Mode, cmd run: Pip install OPENPYXL4  fromOpenpyxlImportWorkbook5 6 #Create a new workbook7WB =Workbook ()8 9 #How to create a new worksheetTen #ws1 = Wb.create_sheet () One  A #grab an active worksheet -WS =wb.active -ws.title="Test Cases" the  - #write data directly into a cell -Xst'A1'] = 42 -  + #add a row of data -Ws.append ([1, 2,"Hello, Pepe! "]) +  A #Python can automatically type conversions at Importdatetime -  -ws['A2'] =Datetime.datetime.now () -  - #convenient operation of a variable cell -D = Ws.cell (row = 5, column = 5) inD.value="Hello, bye! " -  toValue=D.value + Print("This is the data that is read out:", value) -  the #Save the file *Wb.save (R"D:\test\sample.xlsx") $ Panax Notoginseng Print("Save complete! You can open it and watch it! ")

Use Python to read and write versions of Excel2007 and above, from the official demo

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.