xlwings module

xlwings installation

xlwingsLibrary pipinstallation:

在控制台输入 pip install xlwings

xlwings actual operation example

. 1  Import xlwings XW AS
 2  
. 3 WB = xw.Book ( " D: \ Desktop \ New XLSX sheet .xlsx " )     # establish connection excel sheet 
. 4  
. 5 SHT wb.sheets = [ " Sheet1 " ]   # instantiated Worksheet Object 
. 6  
. 7 wb.fullname # returns the worksheet absolute path 
. 8  Print (wb.fullname)
 . 9  
10 sht.name     # returns the name of the work Po 
. 11  Print (sht.name)
 12 is  
13 is sht.range ( ' A1 ' ) .Value = " 123 "     # Write data 123 in cell A1, 
14  
15 sht.range ( ' A1 ' ) .Value        # contents read cell A1 
16  Print (sht.range ( ' A1 ' ) .Value)
 . 17  
18 is sht.range ( ' A1 ' ) .clear () # clearing unit table content and format 
. 19  
20 is sht.range ( ' A1 ' ) .column    # get a cell column index 
21 is sht.range ( ' A1 ' ) .Row      # acquired line marked 
22 is SHT .range ( ' A1 ') .column_width     # Get column width 
23 is sht.range ( ' A1 ' ) .row_height       # acquired line height 
24  Print (sht.range ( ' A1 ' ) .column, sht.range ( ' A1 ' ) .Row, sht.range ( ' A1 ' ) .column_width, sht.range ( ' A1 ' ) .row_height)
 25  
26 is sht.range ( ' A1 ' ) .rows.autofit ()   # line high adaptive 
27 sht.range ( ' A1 ' ). columns.autofit () #Column width adaptive 
28  
29 sht.range ( ' A1 ' ) .color = (34,156,65)    # Give cell A1 the background color 
30  
31 sht.range ( ' A1 ' ) .color    # Return the RGB value of the cell color 
32  Print (sht.range ( ' A1 ' ) .color)
 33 is  
34 is sht.range ( ' A1 ' ) = None .color   # clear cell color 
35  Print (sht.range ( ' A1 ' ) .color)
 36  
37 [ SHT .range ( ' A1 ') .Formula = ' = the SUM (B6: B7) '    # enter the formula, the results of the corresponding cell 
38 is  
39 sht.range ( ' A1 ' ) .formula_array    # acquiring unit cell formula 
40  
41 is sht.range ( ' A1 ' ). = value [[ ' A1 ' , ' A2 ' , ' A3 ' ], [l, 2,3]]   # is written to the designated cell location lot information 
42 is  
43 is sht.range ( ' A1 ' ) .expand (). value   # using the expand () method reads the batch data table 
44 is  Print (sht.range ('A1').expand().value)

 

Guess you like

Origin www.cnblogs.com/sccc/p/12671021.html