60.4.111.* | 4樓 常用語法 xlsheet.Range("A1:I1").Select '選中A1至I1 xlapp.Selection.Merge '合并選中的 xlapp.Selection.HorizontalAlignment = xlCenter '水平居中 啟動(dòng) Excel Dim objExcel As Excel.Application Set objExcel = CreateObject("Excel.Application") objExcel.Visible = True'設(shè)置EXCEL對(duì)象可見(或不可見) 創(chuàng)建有一個(gè)工作表的工作簿 Dim objWorkBook As Excel.WorkBook objExcel.SheetsInNewWorkbook = 1 Set objWorkbook = objExcel.Workbooks.Add 打開已經(jīng)存在的 EXCEL 工件簿文件 Set objWorkbook=objExcel.Workbooks.Open("文件名") 設(shè)置活動(dòng)工作表 Dim objSheet As Excel.Worksheet Set objSheet = objExcel.Worksheets("表名") 給單元格(row,col)賦值 objSheet.Cells(row, col) =值 給合并的單元格賦值,如(A3:A9) objSheet.Range("A3:A9") =值 運(yùn)行 EXCEL 宏 objWorkbook.RunAutoMacros ("宏名") 插入一行 objSheet.Rows("1:1").Insert Shift:=xlDown Range("C8").Select Selection.EntireRow.Insert '在第8行插入 Range("C9").Select Selection.EntireRow.Delete '刪除第9行 range("a1:c3").copy'復(fù)制一塊 range("a5").PasteSpecial'在第a5行處粘貼復(fù)制的塊 xlSheet.Range("C3").Value = "1" xlSheet.Cells(1, 1) = "test中文" '給單元格(row,col)賦值 ' 畫邊框線 xlSheet.Range(xlSheet.Cells(1, 1), xlSheet.Cells(2, 2)).Borders.LineStyle = xlContinuous xlSheet.Rows(1).HorizontalAlignment = xlVAlignCenter '左右居中 xlSheet.Rows(1).VerticalAlignment = xlVAlignCenter '上下居中 xlSheet.Cells(iStartRow + idx, 2).HorizontalAlignment = xlVAlignCenter '左右居中 '設(shè)置指定列的寬度(單位:字符個(gè)數(shù)) xlApp.ActiveSheet.Columns(1).ColumnWidth = 15 '設(shè)置指定行的高度(單位:磅) xlApp.ActiveSheet.Rows(1).RowHeight = 1 / 0.035 '設(shè)置字體 'xlApp.ActiveSheet.Cells(1, 1).Font.Name = "黑體" '設(shè)置字體大小 xlApp.ActiveSheet.Cells(1, 1).Font.Size = 25 '設(shè)置整列字體為粗體 xlApp.ActiveSheet.Columns(1).Font.Bold = True 'xlBook.SaveAs ("C:\Case1.xls") 'xlSheet.PrintPreview (True) xlApp.Visible = True '顯示文件 'xlSheet.PrintOut '打印工作表 xlSheet.PageSetup.LeftHeader = "&""黑體,加粗""&36頁眉"'設(shè)為36號(hào)字體,黑體,加粗'設(shè)置頁眉 |
|