作者:乔山办公网日期:
返回目录:excel表格制作
( 一 ) 使用动态创建的方法
首先创建 Excel 对象,使用ComObj :
Var
ExcelApp : Variant ;
ExcelApp := CreateOleObject ( '' Excel.Application '' ) ;
1 ) 显示当前窗口:
ExcelApp.Visible := True ;
2 ) 更改 Excel 标题栏:
ExcelApp.Caption := '' 应用程序调用 Microsoft Excel '' ;
3 ) 添加新工作簿e79fa5e98193e58685e5aeb9330:
ExcelApp.WorkBooks.Add ;
4 ) 打开已存在的工作簿:
ExcelApp.WorkBooks.Open ( '' C : \Excel\Demo.xls '' ) ;
5 ) 设置第2个工作表为活动工作表:
ExcelApp.WorkSheets [ 2 ] .Activate ;
或
ExcelApp.WorksSheets [ '' Sheet2 '' ] .Activate ;
6 ) 给单元格赋值:
ExcelApp.Cells [ 1 , 4 ] .Value := '' 第一行第四列 '' ;
7 ) 设置指定列的宽度(单位:字符个数),以第一列为例:
ExcelApp.ActiveSheet.Columns [ 1 ] .ColumnsWidth := 5 ;
8 ) 设置指定行的高度(单位:磅)(1磅=0.035 厘米),以第二行为例:
ExcelApp.ActiveSheet.Rows [ 2 ] .RowHeight := 1 / 0.035 ; // 1厘米