var
ExcelAPP :Variant;
begin
ExcelApp := CreateOleObject(‘Excel.Application’);
…//Excel相关操作。例如新建,删除,保存等
end;
1.新建Excel工作表
ExcelApp.WorkBooks.Add;
2.打开已经存在的Excel 文件
ExcelApp.WorkBooks.open(‘../../Demo.xlsx’);
3.新增Sheet
ExcelApp.WorkSheets.Add(after/Before:=ExcelAPP.workSheets[1]);
4.文件另存为
ExcelApp.ActiveWorkBooks.SaveAs(‘../../Notimportant.xlsx’);
5.打开Excel工作区域
ExcelApp.visible := true;
6.Excel文件中sheet改名
ExcelApp.WorkSheets[1].Name := ‘NotImportant’;
7.设置当前使用的Sheet
ExcelApp.WorkSheets[1].activate;
8.Excel工作表中填写数据
ExcelApp.cells[1,1] := ‘HelloWorld!’;
9.工作表关闭
ExcelApp.WorkBooks.Close;
10.退出Excel
ExcelApp.Quit;
11.合并单元格
ExcelApp.workSheets[1].range[‘A1:B1’].Merge(True);//合并行
ExcelApp.WorkSheets[2].range[‘A2:A3’].Merge(true);//合并列
Excel操作分为以下几个步骤:
1.生成ExcelApp对象
2.创建可用的Excel工作区域。
3.创建sheet
4.填写数据
5.保存文件
6.关闭Excel工作区域
7.退出ExcelAPP
本文介绍使用 VCL 创建和操作 Excel 文件的方法,包括新建、打开、保存文件,添加及修改工作表,填写数据,合并单元格等常见操作。
1万+

被折叠的 条评论
为什么被折叠?



