python-- use Excel xlwing library operation

Excel is essential now than data processing software, python has a lot of support operations Excel library, xlwing is one of them.

xlwings installation

xlwingsLibrary pipinstallation:

在控制台输入 pip install xlwings

Actual operation example xlwings

Import xlwings XW AS 

WB = xw.Book ( " D: \ Desktop \ New XLSX sheet .xlsx " )     # establish connection excel sheet 

SHT = wb.sheets [ " Sheet1 " ]   # instantiated Worksheet Object 

wb.fullname # Returns sheet absolute path 
Print (wb.fullname) 

sht.name     # returns the name of the work Po 
Print (sht.name) 

sht.range ( ' A1 ' ) .Value = " 123 "      # in cell A1, the write data 123 

SHT. Range ( ' A1 ' ) .Value        # reading the contents of cell A1
Print (sht.range ( ' A1 ' ) .Value) 

sht.range ( ' A1 ' ) .clear () # clearing unit table content and format 

sht.range ( ' A1 ' ) .column    # get a cell column index 
sht. Range ( ' A1 ' ) .Row      # acquired line marked 
sht.range ( ' A1 ' ) .column_width     # Get column width 
sht.range ( ' A1 ' ) .row_height       # acquired line height 
Print (sht.range ( ' A1 ' ) .column, sht.range (' A1 ' ) .Row, sht.range ( ' A1 ' ) .column_width, sht.range ( ' A1 ' ) .row_height) 

sht.range ( ' A1 ' ) .rows.autofit ()   # line high adaptive 
sht. Range ( ' A1 ' ) .columns.autofit () # column width adaptive 

sht.range ( ' A1 ' ) = .color (34,156,65)    # to the background color of the cell A1 

sht.range ( ' A1 ' ). color    # returns the cell color RGB values 
Print (sht.range ( ' A1 ' ).color)

sht.range ( ' A1 ' ) = None .color   # clear cell color 
Print (sht.range ( ' A1 ' ) .color) 

sht.range ( ' A1 ' ) .Formula = ' = the SUM (B6: B7) '    # enter the formula, the corresponding cell in the execution result 

sht.range ( ' A1 ' ) .formula_array    # acquiring unit cell formula 

sht.range ( ' A1 ' ) .Value = [[ ' A1 ' , ' A2 ' , ' A3 ' ], [1,2,3]]   #Batch writing information to a specified cell position 

sht.range ( ' A1 ' ) .expand (). Value   # using the expand () method reads the batch data table 
Print (sht.range ( ' A1 ' ) .expand (). value)

Practical results were as follows

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/hyz1900457346/p/11871377.html