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) 设置指定列的宽度(单位:字符个数),以第一列为例: 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单位默认为字符数; 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.打印单元格网线: xlSheet.PageSetup.PrintGridLines = True; 15) 拷贝操作: a.拷贝整个工作表: xlSheet.Used.Range.Copy; b.拷贝指定区域: 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》