langue:VB
date:2020-04-02
Set ExcelApp = CreateObject( "Excel.Application" ) ’创建资源,建立连接
Set ExcelBook = ExcelApp. Workbooks. Open( “d: \pipo\index. htm")
Set ExcelSheet = ExcelBook. Worksheets( 1 )
With ExcelSheet
. Range( "B" & i) = "如何写内容"
'. Range( "B7:G38" ) = "选择范围"
ExcelSheet. Range( "G" & i) . Select '选择单元格范围
ExcelApp. Selection. NumberFormatLocal = "yyyy-mm-dd hh:mm:ss" '自定义日期格式
ExcelApp. Selection. NumberFormatLocal = "@" '文本格式
. Range( "G" & i) = "相信我,这里的内容马上就要变成 仿宋 14size 加粗 了"
ExcelApp. Selection. Font. Name = "仿宋"
ExcelApp. Selection. Font. Size = 14
ExcelApp. Selection. Font. Bold = True
ExcelSheet. PageSetup. PrintArea = "$A$1:$H$39" '选择打印范围,开始打印页面设置
ExcelSheet. PageSetup. CenterHorizontally = 2 / 0.035 '水平居中
ExcelSheet. PageSetup. CenterVertically = 2 / 0.035 '垂直居中
ExcelSheet. PageSetup. Zoom = False '缩放大小0 - 100 , 这里不使用它
ExcelSheet. PageSetup. FitToPagesWide = 1 '调整内容至1 页宽
ExcelSheet. PageSetup. FitToPagesTall = 1 '调整内容至1 页高
End With
ExcelBook. Save
ExcelBook. Close
Set ExcelSheet = Nothing ‘释放内存,归还资源,这很重要
Set ExcelBook = Nothing
Set ExcelApp = Nothing