Python merges multiple Excel data

Source: Internet
Author: User

Mounting module

1, find the corresponding module http://www.python-excel.org/

2. Installing with PIP Install

Pip Install Xlrd
Pip Install Xlsxwriter

Pip List View

Xlsxwriter Example
1 ImportXlsxwriter2 3 #Create a workbook and add a worksheet4Workbook = Xlsxwriter. Workbook ("demo.xlsx")5Worksheet =Workbook.add_worksheet ()6 7 #Set column widths8Worksheet.set_column ("a:a", 20)9 Ten #Set Format OneBold = Workbook.add_format ({"Bold": True}) A  - #set the value of a cell -Worksheet.write ("A1","Hello") the  - #formatted Cells -Worksheet.write ("A2"," World") -  + #write some numbers, identify them with rows and columns -Worksheet.write (2, 0, 123) +Worksheet.write (3, 0, 123.456, Bold) A  at #Insert a picture -Worksheet.insert_image ("B5","C:/users/cheng/desktop/1.png") -  - #Close File Stream -Workbook.close ()

The results of the operation are as follows:

Thinking of merging Excel data

Excel is made up of rows and columns, so here all the data in all the sheet in all the files is read out to form a two-dimensional array and then write to the new Excel

Code
1 Importxlrd2 ImportXlsxwriter3 4Source_xls = ["d:/python/1.xlsx","d:/python/2.xlsx"]5Target_xls ="d:/python/3.xlsx"6 7 #reading Data8data = []9  forIinchSource_xls:TenWB =Xlrd.open_workbook (i) One      forSheetinchwb.sheets (): A          forRowNuminchRange (sheet.nrows): - data.append (Sheet.row_values (rownum)) - Print(data) the #Write Data -Workbook =Xlsxwriter. Workbook (Target_xls) -Worksheet =Workbook.add_worksheet () -Font = Workbook.add_format ({"font_size": 14}) +  forIinchRange (len (data)): -      forJinchRange (len (data[i)): + Worksheet.write (i, J, Data[i][j], font) A #Close File Stream atWorkbook.close ()
Run results

Experience

Just started to learn python, probably because of the Java code to see the reason, beginners feel grammar strange, and Java some similar, and feel and javascript,perl this kind of like ...

It's an object-oriented, interpretive, high-level programming language!!!

Python merges multiple Excel data

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.