I am using Excel2000, which must be referenced in the project: Add reference-> Com-> Microsoft Excel 9.0 Object Library
1 open Excel dim myexcel as new Excel. Application () myexcel. visible = true
2. add new workbook myexcel. Workbooks. add ()
3. Set the second worksheet as the active worksheet myexcel. worksheets (2). Acivate ()
4. open the specified Excel file myexcel. workbooks. open ("c: \ my.xls ")
5. Show the Excel window myexcel. visible = true
6. Change the title bar of Excel. myexcel. caption = "Welcome! "
7. Assign the value of myexcel to the cells in Excel. cells (1, 4 ). value = 100 this statement makes the fourth column of the first row of the current Excel worksheet, that is, the D1 cell is equal to 100, you can also write: myexcel. range ("D1 "). value = 100
8. Set the width of the specified column (unit: number of characters). myexcel. ActiveSheet. colums (1). columnwidth = 20. Set the width of the 1st column of the current worksheet to 20.
9 set the height of the specified row (unit: lbs) myexcel. ActiveSheet. rows (1). rowHeight = 1/0. 035 1 lb = 0.035 CM set the height of 1st rows to 1 CM
10 insert a page break myexcel. Activesheet. rows (20). pagebreak = 1 insert a page break before 20th rows
11 Delete the Page Break myexcel. Activesheet. columns (20). pagebreak = 0 Delete the page break before the 20th Column
12. Specify the border line width myexcel. activesheet. range ("B3: D3 "). borders (1 ). weight = 3 where the borders parameter specifies the cell border position: 1: Left 2: Right 3: Top 4: bottom 5: Oblique \ 6: Oblique/
13. Specify the border line type myexcel. activesheet. range ("B1: D3 "). borders (2 ). linestyle = 1 This statement sets the right border of cell B1: D3 of the current worksheet to the solid line linestyle parameter: 1: solid line 2: dotted line 3: dotted line 4: double solid line
14 set the footer myexcel. activesheet. pagesetup. centerfooter = "Page & p" NOTE: When setting the footer, ensure that a printer is installed on the computer; otherwise, an error occurs!
15 set the header myexcel. activesheet. pagesetup. centerfooter = "Page & p"
16 set the maximum disconnection distance from the header to 2 cm myexcel. Activesheet. pagesetup. Headermargin = 2/0. 035
17 set the footer end distance to 2 cm myexcel. Activesheet. pagesetup. Footermargin = 2/0. 035
18 set the top edge margin to 2 cm myexcel. Activesheet. pagesetup. topmargin = 2/0. 035
19 set the bottom edge margin to 2 cm myexcel. Activesheet. pagesetup. Bottommargin = 2/0. 035
20 set the left margin to 2 cm myexcel. Activesheet. pagesetup. Leftmargin = 2/0. 035
21. Set the right margin to 2 cm myexcel. Activesheet. pagesetup. Rightmargin = 2/0. 035.
22 set the horizontal center of the page. myexcel. activesheet. pagesetup. CenterHorizontally = true
23 set vertical center of page myexcel. activesheet. pagesetup. Centervertically = true
24 set the page size (1, narrow rows 8.5*11; 39, wide rows 14*11) myexcel. activesheet. pagesetup. papersize = 1
25 print the cell gridline myexcel. activesheet. pagesetup. PrintGridlines = true
26 Copy the entire worksheet myexcel. activesheet. Usedrange. Copy
27 Copy myexcel. activesheet. range ("a1: b5"). Copy
28 paste myexcel. worksheets ("sheet2"). range ("A1"). PasteSpecial
29 Insert a row of myexcel. activesheet. rows (2). Insert in front of row 2nd
30 Insert a column of myexcel. Activesheet. Columns (2). Insert in front of Column 2nd
31 Merge C4: D4 Cell myexcel. Activesheet. Range ("C4: D4"). Merge ()
32 automatically adjust 2nd column width myexcel. activesheet. Columns (2). AutoFit
33 set the font myexcel. Activesheet. cells (). font. name = ""
34 set the font size myexcel. Activesheet. cells (). font. size = 25
35. Set the font to myexcel. Activesheet. cells (). font. Italic = true.
36 set the font to Bold myexcel. Activesheet. cells (). font. Bold = true
37 clear the cell content myexcel. activesheet. cells (). ClearContents
38 print preview worksheet myexcel. Activesheet. PrintPreview
39 print the worksheet myexcel. Activesheet. Printout
40 Save the worksheet as myexcel. ActiveWorkbook. saveas ("C: \ book2.xls ")
41 discard the storage disk myexcel. ActiveWorkbook. saved = false
42 close the workbook myexcel. Workbooks. close
43 exit Excel myexcel. quit
With these commands clear, it is easy to operate excel!