用EXCEL做好报表的模板,如何用DELPHI来调用它,并实现打印预览及打印的功能。

如题所述

把EXCEL放在delphi 应用程序(.exe)同个目录然后
begin
var
excel, WorkBook, Sheet: Variant;
try
excel := CreateOleObject('Excel.Application');
WorkBook := excel.Workbooks.Add(extractfilepath(application.exename) + '\xxxxx.xls');
Sheet := WorkBook.Worksheets[1];
except
excel := NULL;
ShowMessage('请先安装Excel');
EXIT;
end;
try
Sheet.cells(5, 2) := '15484151'; //表示第5行第2列写入15484151字符

.........
.......
finally
end;
try
excel.Visible := true;
WorkBook.Saved := True;
finally
//excel.Quit;
//excel := Unassigned;
end;
end;

就这样可以了很简单的!
温馨提示:答案为网友推荐,仅供参考
相似回答