Recently, I encountered such a problem in my work. I had to deal with the following batch of Excel forms every day: there was only one sheet in each form, the first two lines of which were the title and header of the form, and the last line of the form was signed by relevant personnel. The ultimate goal is to merge the contents of each table into an Excel table, making it a single table. Copying and pasting takes up most of the day. The table looks like this:

Requirement analysis According to the description, the final requirement should be like this: select the first two rows of any table in this batch as the title and header of the new table, and insert these two rows into an empty list named Data as a nested list. Take the third to last rows of each table and eliminate the blank rows. Insert the contents of all tables into the data list as sublists. Insert the last row of any table into the data list as a sublist. Finally, write the contents of the data list into a new Excel table.

After a few minutes of searching online, the following conclusions can be drawn: -3.1 The XLRD and XlsxWriter modules can solve the requirements;

  • 3.2 The reason why XLRD and XlsxWriter are used is that XLRD is good at reading Excel files and is not suitable for writing. No error will be reported when xlsxWriter is used to write Excel tables on a large scale.

Code everything to solve the current problem as a guide, just do it. coding … .

Read the original access code: developer.aliyun.com/ask/268253?…