In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
As a member of excel, openpyxl is easy to use and has a wide range of functions.
Environment:
Win 10
Python 3.6
Pip 9.0.1
Openpyxl 2.4.8
Install openpyxl
Open the cmd command line, enter pip install openpyxl, and press enter to execute the command.
Study
Create an excel file (Create a workbook)
First import the Workbook in the openpyxl library
From openpyxl import Workbookwb = Workbook ()
Create worksheet (Create sheet)
Ws = wb.create_sheet (title='math',index=0)
Parameter description:
Title, defining the sheet name
Index, which defines the sort location of the new sheet. When this parameter is omitted, the newly created sheet is added to the last.
Access cells (Accessing one cell)
# method1ws ['A4'] = 4 # method2d = ws.cell (row=4, column=2, value=10)
The method of accessing the cell is the same as excel, and you can use the method of A1 Magi B12.
Access unit block (Accessing many cells)
# method1cell_range = ws ['A _ 1 _ blank _ virtual _ D2'] # method2ws.iter_rows (min_row=1,max_row=3, min_col=2,max_col=3) # selected cell block of A1:C3
Data storage (data storage)
C = ws ['A12'] c.value =' hellos'
Save file (save file)
Wb.save ('balances.xlsx')
Load Fil
From openpyxl import load_workbookwb = load_workbook ('..\..\\ file\\ math.xlsx') print (wb.get_sheet_names ())
learn in order to practise
From openpyxl import Workbook# create a new workbootwb = Workbook () # create a sheet,sheetname is math, put it in the first position ws = wb.create_sheet ('math',0) m = access the cell block using the method Assign for row in ws.iter_rows (min_row=1,max_row=9,min_col=1,max_col=9) to the cell while traversing: # for row in ws ['A11 for cell in row for cell in row I19']: cell n = 0 cell: n=n+1 cell.value=m*nwb.save ('..\..\\ file\\ math.xlsx')
Using the method of accessing the cell block, the 99 multiplication table is implemented, and the result is as follows:
references
Https://openpyxl.readthedocs.io/en/latest/tutorial.htm
Supplementary explanation
When looking at the materials, I also found an article, compared with a variety of excel libraries, good articles, stay and read.
Http://www.jianshu.com/p/be1ed0c5218e
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.