来源:http://blog.csdn.net/newgrammer/archive/2006/04/03/501058.aspx

        '1.打开Excel
        Dim exl As New Excel.Application()
        exl.Visible = True

        '2.添加工作簿
        exl.Workbooks.Add()

        '3.设定活动工作表
        'exl.Worksheets("sheets").active()

        '4.打开指定的Excel文件
        'exl.Workbooks.Open("c:\book1.xls")

        '5.显示Excel窗口
        exl.Visible = True

        '6.更改标题栏
        exl.Caption = "aaaaaaaaaaa"

        '7.为单元格赋值
        exl.Cells(1, 4).value = 100
        exl.Range("a1:b5").Value = 50

        '8.设置指定列宽度
        exl.ActiveSheet.columns(1).columnwidth = 20

        '9.设行高
        exl.ActiveSheet.rows(1).rowheight = 1 / 0.035

        '10.在第18行插入分页
        exl.ActiveSheet.rows(18).pagebreak = 1

        '11.在第4列前删除分页符
        exl.ActiveSheet.columns(4).pagebreak = 0

        '12.指定边框线的宽度
        exl.ActiveSheet.range("b3:d3").borders(2).weight = 3

        '13.边框线条类型
        Dim sheet As Excel.Worksheet
        sheet = exl.ActiveSheet
        sheet.Range("b10:f13").Borders(Excel.XlBordersIndex.xlEdgeBottom).LineStyle = 1

        '14.设置页脚
        sheet.PageSetup.CenterFooter = "第&p页"

        '15.页眉
        sheet.PageSetup.CenterHeader = "aaaaaa"

        '16.顶、底、左、右边距
        sheet.PageSetup.HeaderMargin = 2 / 0.035
        sheet.PageSetup.FooterMargin = 2 / 0.035
        sheet.PageSetup.LeftMargin = 2 / 0.035
        sheet.PageSetup.RightMargin = 2 / 0.035
        '页眉距顶端、页脚距底边
        sheet.PageSetup.HeaderMargin = 2 / 0.0354
        sheet.PageSetup.FooterMargin = 2 / 0.035

        '22.页面水平居中
        sheet.PageSetup.CenterHorizontally = True
        '23.页面垂直居中
        sheet.PageSetup.CenterVertically = True

        '24.页面纸张
        sheet.PageSetup.PaperSize = Excel.XlPaperSize.xlPaperA4

        '25.打印网格(边框是实线,中间是虚线)
        sheet.PageSetup.PrintGridlines = True

        '26.复制整个工作表
        sheet.Range("a1:f5").Copy()
        sheet.Range("a10").PasteSpecial() '粘贴

        '29.插入列/行
        sheet.Columns(1).insert()
        sheet.Rows(1).insert()

        '31.合并格
        sheet.Range("c4:d4").Merge()

        '33.调整字体
        'sheet.Cells("a1: f10").font.name = 5

        '38.打印预览
        exl.ActiveWorkbook.PrintPreview()

        '39.打印
        exl.ActiveWorkbook.PrintOut()

        '40.保存文件
        exl.ActiveWorkbook.SaveAs("e:\aa.xls")

        '41.放弃存盘
        exl.ActiveWorkbook.Saved = True

        '43.退出
        exl.Quit()

posted on 2006-06-07 22:03  YuL  阅读(655)  评论(0编辑  收藏  举报