|
1) 顯示當前窗口: xlSheet.Visible = True; 2) 更改 Excel 標題欄: xlSheet.Caption = '應用程序調用 Microsoft Excel'; 3) 添加新工作簿: xlSheet.WorkBooks.Add; 4) 打開已存在的工作簿: xlSheet.WorkBooks.Open( 'd:\Demo.xls' ); 5) 設置第2個工作表為活動工作表: xlSheet.WorkSheets[2].Activate; 或 xlSheet.WorksSheets[ 'Sheet2' ].Activate; 6) 給單元格賦值:xlSheet.Cells[1,4].Value = 'http://blog.soso.com/qz.q/第一行第四列'; xlSheet.Cells(2,j+1).Interior.Color = 50000 ;//設置單元格背景顏色 7) 設置指定列的寬度(單位:字符個數(shù)),以第一列為例: xlSheet.Columns[1].ColumnsWidth = 5; 8) 設置指定行的高度(單位:磅)(1磅=0.035厘米),以第二行為例: xlSheet.Rows[2].RowHeight = 1/0.035; // 1厘米 9) 在第8行之前插入分頁符: xlSheet.WorkSheets[1].Rows[8].PageBreak = 1; 10) 在第8列之前刪除分頁符: xlSheet.Columns[4].PageBreak = 0; 11) 指定邊框線寬度: xlSheet.Range[ 'B3:D4' ].Borders[2].Weight = 3; 1-左 2-右 3-頂 4-底 5-斜( \ ) 6-斜( / ) 12) 清除第一行第四列單元格公式: xlSheet.Cells[1,4].ClearContents; 13) 設置第一行字體屬性: xlSheet.Rows[1].Font.Name = '隸書'; xlSheet.Rows[1].Font.Color = clBlue; xlSheet.Rows[1].Font.Bold = True; xlSheet.Rows[1].Font.UnderLine = True; xlSheet.Range("A1:G1").Merge(); //合并單元格 14) 進行頁面設置: xlSheet.PageSetup.FirstPageNumber=1;/ /從首頁開始打印 xlSheet.PageSetup.Orientation=2;//設置為橫向打印 xlSheet.PageSetup.PrintTitleRows = "$2:$2";//固定打印表頭 a.頁眉: 注:這里要注意,如果是Wps ET,Margin的單位默認為像素,要注意一下所給的值,別超出合理范圍;而Excel單位默認為字符數(shù); xlSheet.PageSetup.CenterHeader = '報表演示'; b.頁腳: xlSheet.PageSetup.CenterFooter = '第&P頁---------共(&N)頁'; c.頁眉到頂端邊距2cm: xlSheet.PageSetup.HeaderMargin = 2/0.035; d.頁腳到底端邊距3cm: xlSheet.PageSetup.HeaderMargin = 3/0.035; e.頂邊距2cm: xlSheet.PageSetup.TopMargin = 2/0.035; f.底邊距2cm: xlSheet.PageSetup.BottomMargin = 2/0.035; g.左邊距2cm: xlSheet.PageSetup.LeftMargin = 2/0.035; h.右邊距2cm: xlSheet.PageSetup.RightMargin = 2/0.035; i.頁面水平居中: xlSheet.PageSetup.CenterHorizontally = 2/0.035; j.頁面垂直居中: xlSheet.PageSetup.CenterVertically = 2/0.035; k.打印單元格網(wǎng)線: xlSheet.PageSetup.PrintGridLines = True; 15) 拷貝操作: a.拷貝整個工作表: xlSheet.Used.Range.Copy; b.拷貝指定區(qū)域: xlSheet.Range[ 'A1:E2' ].Copy; c.從A1位置開始粘貼: xlSheet.Range.[ 'A1' ].PasteSpecial; d.從文件尾部開始粘貼: xlSheet.Range.PasteSpecial; 16) 插入一行或一列: a. xlSheet.Rows[2].Insert; b. xlSheet.Columns[1].Insert; 17) 刪除一行或一列: a. xlSheet.Rows[2].Delete; b. xlSheet.Columns[1].Delete; 18) 打印預覽工作表: xlSheet.PrintPreview; 19) 打印輸出工作表: xlSheet.PrintOut; 20) 工作表另存為: workbookData.Saved = true; xlSheet.SaveAs(filename, missing, missing, missing, missing, missing, missing, missing, missing, missing); 21) 關閉工作簿: workbookData.Close(false, missing, missing); 22) 退出 Excel: myExcel.Quit(); |
|
|
來自: goodwangLib > 《Excel》