python library use xlwings processing efficiency and other excel Summary - continuously updated

xlwings Getting Started guide and use

I compared openxl and xlwings official documents, found xlwings official website API is clear and concise,
if you are just getting started, do not go to Baidu in accordance with the function to search a sentence to the splicing code
direct spend an hour a look API interface specification, basically you will be used
at the same time, the official website also put some small examples to get you started
xlwings official website API specification
, for example some operations module

Open xlsx file and process a close

import xlwings as xlw
app = xlw.App(visible=True, add_book=False)
app.display_alerts = False
 app.screen_updating = False # excel whether to show content
 wb = app.books.open(self.XlsPath)

procxls () # personal process

 wb.save () after saving treatment #
 wb.close () # close the file handle to write to the file
 app.quit () # close the app

  

Write multiple rows of data

Store list
List # [2,3] is stored in the A1: C1 in
sht.range('A1').value=[1,2,3]
# The list [1,2,3] stored in A1: A3 in
sht.range('A1').options(transpose=True).value=[1,2,3]
# The 2x2 table, i.e. two-dimensional array stored in A1: B2, as a first line 1, a second row 3,4
sht.range('A1').options(expand='table')=[[1,2],[3,4]]

  

options () function, Chinese documents rarely described clearly, suggest that you go to the official website, do not be misled

xlwings Advanced Interface

As for some simple operations, it has been written very much blog, I will give you the lead over, it is no longer described in detail here

Some read xlwings, writing table API usage, Chinese blog address

Efficiency

Start efficiency

open (start win environment that comes with office-excel Setup program) (equivalent to help you open the excel table to operate on); this efficiency depends on your own computer performance, are generally required to take about 3s, I tried I had a little old notebook to 5s;

app = xlw.App(visible=True, add_book=False)
app.display_alerts = False
app.screen_updating = False # excel whether to show content
wb = app.books.open(self.XlsPath)

  

Refresh efficiency

app.screen_updating = False option is to configure the display content is refreshed in real time excel program,
if the distribution is True, I observed would lead to about three times slower.

Interface to read and efficiency recommendations

To excel in reading, writing, basically through

sht.range ( "A1"). value [read]
sht.range ( "A1"). value = ' Hello' [writing]
this side can have personality problems, if you are a cell in a cell to read and write, especially slow, I read + write cycle 2000 cells, the basic time-consuming 30s
, however, if you batch reading, writing, and soon will be able to become, for example: a read, write an entire row

sht.range ( "A1: Z1") value [read].
sht.range. ( "A1: Z1") value = ( 'Hello', 'hello', 'hello', ...) [write]
so to improve efficiency, we should try to bulk operations

Color read and write performance and disadvantages

Top proved bulk operations to improve efficiency, however, read and write accurate color have a place, do not support batch operations

sht.range ( "A1"). color [read]
sht.range ( "A1"). color = (210, 67, 9) [write]
project I do, needs to be based on the color table to do different operations (modifications , delete, etc.), can only lead to one cell cycle cell to traverse



Original: https: //blog.csdn.net/wskzgz/article/details/89181501

Guess you like

Origin www.cnblogs.com/qbdj/p/11010812.html