Python+win32--com Implementing Excel Automation

Source: Internet
Author: User
Tags win32


Import win32com

App_type = ' Excel.Application '

Xlblack,xlred,xlgray,xlblue = 1,3,15,41
Xlbreakfull = 1

#初始化应用程序
XLS = Win32com.client.Dispatch (app_type)
Xls. Visible = True
Book = xls. Workbooks.Add ()
Sheet = Book. Worksheets (1)

#插入标题
Row_per_page,col_per_row = 10, 10
Row_index,col_index = 1
Title_range = sheet. Range (sheet. Cells (row_index,col_index), sheet. Cells (Row_index, Col_per_row))
Title_range. MergeCells = True
Title_range. Font.bold,title_range. Interior.ColorIndex = True,xlgray
Title_range. Value = ' Hello,word '
Row_index + = 1

The sequence of #插入内容 10*10
For row in range (0, 10):
Col_index = 1
For Col in range (0, Col_per_row):
Cell_range = sheet. Cells (Row_index, Col_index)
Cell_range. Font.color,cell_range. Value = Xlblue,str (Row)
Row_index + = 1

#插入分页符
Right_bottom_range = sheet. Cells (Row_index, col_per_row+1)
Right_bottom_range. PageBreak = Xlbreakfull

#插入图片
Col_index = 1
Lt_range = sheet. Cells (Row_index, Col_index)
Graph_width = sheet. Range (sheet. Cells (row_index,1), sheet. Cells (Row_index, Col_per_row)). Width
Graph_height = sheet. Range (sheet. CellS (row_index,1), sheet. Cells (Row_index+row_per_page, 1)). Height
Sheet. Shapes.addpicture (' c:\\test.jpg ', False, True, Lt_range. Left, Lt_range. Top, Graph_width, Graph_height)

Python+win32--com Implementing Excel Automation

Related Article

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.