C # Set common Excel attributes.

Source: Internet
Author: User

 

* 1. Create an Excel Object
EOLE = Createobject ('excel. application ')

* 2. Add a new workbook

EOLE. workbooks. Add

Activate a specified workbook
EOLE. worksheets ("workbook name"). Activate

* 3. Set 3rd worksheets to activate worksheets.

EOLE. worksheets ("sheet1"). Activate

* 4. Open a specified workbook

EOLE. workbooks. Add ("E:/e_temp/abc.xls ")

* 5. display the Excel window

EOLE. Visible =. T.

* 6. Change the Excel title bar

EOLE. Caption = "VFP Application calls Microsoft Excel"

* 7. assign values to cells

* EOLE. cells (row, column). value = xm (XM is the database field name)
EOLE. cells (). value = 'asdfasdfasdfasdfadsf'

* 8. Set the width of the specified column (unit: number of characters)

EOLE. activesheet. Columns (1). columnwidth = 5

* 9. Set the height of the specified row (unit: lbs)

EOLE. activesheet. Rows (1). rowheight = 1/0. 035 & set the Row Height to 1 cm, 1 lb = 0.035 cm

* (Set the Row Height to 1 cm, 1 lb = 0.035 cm)

* 10. Insert a paging character before the first row.

EOLE. worksheets ("sheet1"). Rows (18). pagebreak = 1

* 11. Delete the paging character before the 4th column

EOLE. activesheet. Columns (4). pagebreak = 0

* 12. Specify the border line width (the borders parameter is as follows)

EOLE. activesheet. Range ("B3: D3"). Borders (2). Weight = 3

* 13. Set the four border line types

EOLE. activesheet. Range ("B3: D3"). Borders (1). linestyle = 1

* (Borders parameters: 1-left, 2-right, 3-top, 4-bottom, 5-oblique, 6-oblique/; linestyle
Values: 1 and 7, 2, 4, and 9)

* 14. Set the header

EOLE. activesheet. pagesetup. centerheader = "Report 1"

* 15. Set the footer

EOLE. activesheet. pagesetup. centerfooter = "Page & P"

* 16. Set the header to the top margin to 2 cm

EOLE. activesheet. pagesetup. headermargin = 2/0. 035

* 17. Set the footer margin to 3 cm

EOLE. activesheet. pagesetup. footermargin = 3/0. 035

* 18. Set the top margin to 2 cm.

EOLE. activesheet. pagesetup. topmargin = 2/0. 035

* 19. Set the bottom margin to 4 cm.

EOLE. activesheet. pagesetup. bottommargin = 4/0. 035

* 20. Set the left distance to 2 cm

EOLE. activesheet. pagesetup. leftmargin = 2/0. 035

* 21. Set the right margin to 2 cm

EOLE. activesheet. pagesetup. rightmargin = 2/0. 035

* 22. Set the horizontal center of the page

EOLE. activesheet. pagesetup. centerhorizontally =. T.

* 23. Set the vertical center of the page

EOLE. activesheet. pagesetup. centervertically =. T.

* 24. Set the page size (1-narrow Row 8? 5? 11 39-Wide Row 14? 11)

EOLE. activesheet. pagesetup. papersize = 1

Can be one of the following xlpapersize constants (some printers may not support all the paper sizes );
Constant Value meaning;
Xlpaperletter 1 letter (8-1/2 in. x 11 in .)
Xlpapera3 8 A3 (297mm x 420mm)
Xlpapera4 9 A4 (210mm x 297mm)
Xlpapera4small 10 A4 small (210x297)
Xlpapera5 11 A5 (148x210)
Xlpaperb4 12 B4 (250mm x 354mm)
Xlpaperb5 13 B5 (182mm x 257mm)
Xlpaperfanfoldus 39 U. S. Standard Fanfold (14-7/8 in. x 11 in .)
Xlpaperuser User-Defined

* 25. Print the cell network cable

EOLE. activesheet. pagesetup. printgridlines =. T.

* 26. Copy the entire Worksheet

EOLE. activesheet. usedrange. Copy

* 27. Copy a specified region

EOLE. activesheet. Range ("A1: E2"). Copy

* 28. Paste

EOLE. worksheets ("sheet2"). Activate

EOLE. activesheet. Range ("f1"). pastespecial

* 29. Insert a row before row 2nd

EOLE. activesheet. Rows (2). insert

* 30. Insert a column before Column 2nd

EOLE. activesheet. columns (2). insert

* 31. Set the font

EOLE. activesheet. cells (2, 1). Font. Name = ""

* 32. Set the font size

EOLE. activesheet. cells (1, 1). Font. size = 25

* 33. Set the font to italic.

EOLE. activesheet. cells (1, 1). Font. italic =. T.

* 34. Set the font of the entire column to bold.

EOLE. activesheet. Columns (1). Font. Bold =. T.

35. Merge cells. Important!
_ Ole_excel.worksheets ("workbook name"). Range (range). merge & the range must specify the start and end cells, such as "A1: B4"

EOLE. activesheet. Range ("A1: B4"). merge & merge the specified range in the current Worksheet

36. Undo the merge cell operation.
_ Ole_excel.worksheets ("workbook name"). Range (range). unmerge

37. set formulas in cells (important, which can be used for calculation, aggregation, and averaging)
_ Ole_excel.cells (row, column). value = "= formula" & use all VBA internal functions, such as sum. Note: VFP functions cannot be used!

* 35. Clear the cell Formula

EOLE. activesheet. cells (1, 4). clearcontents

* 36. Print the preview Worksheet

EOLE. activesheet. printpreview

* 37. Print the output Worksheet

EOLE. activesheet. Printout

* 38. The worksheet is also

EOLE. activeworkbook. saveas ("C:/temp/22.xls ")

* 39. Discard the disk

EOLE. activeworkbook. Saved =. T.

* 40. Close the workbook
Wait window 'asdfasdf'
EOLE. workbooks. Close

* 41. Exit Excel

EOLE. Quit

From: http://blog.csdn.net/lxl_sports/article/details/5836028

 

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.