如何将infoPower的wwDbGrid产生的数据送到excel,并用excel预览打印呢?(100分)

  • 主题发起人 主题发起人 chenxihua
  • 开始时间 开始时间
C

chenxihua

Unregistered / Unconfirmed
GUEST, unregistred user!
如何将infoPower的wwDbGrid产生的数据送到excel,
并在程序中调用excel的预览打印功能呢?
 
请大家帮帮我
分值100可能太低了,我想加到300,怎么处理呢?
 
在线等待中.....
 
[:(]
怎么没人理我呢?
 
with ExpGrid.ExportOptions do
begin
FileName := 'test.xls';
Save;
ShellExecute(Handle, 'OPEN', PChar(ExpGrid.exportoptions.Filename), nil, nil, sw_shownormal);
end;
 
調用wwdbgrid的save方法, 設置ExportOptions屬性, 裏面是導出選項,
把文件名改爲.xls後綴, 保存后調用shellexecute打開。

uses shellapi;
 
多谢bluedog,我知道保存成excel的办法,

但是如果我想直接把数据以流的形式传给excel,然后调用excel的打印预览功能

该如何做呢?
 
不好意思,问题已经解决了,多谢bluedog的启发,100分给你了
我采用的方法是:
1.保存wwDbGrid内容到临时文件:
function CreateTmpFile(var TmpFileName:String):boolean;
var ptmpPathName,ptmpFileName:Pchar;
begin
result := false;
try
GetMem(ptmpPathName,256);
GetMem(ptmpFileName,256);
GetTempPath(40,ptmpPathName);
GetTempFileName(ptmpPathName,pchar('cashcheck '),0,ptmpFileName);
TmpFileName := StrPas(ptmpFileName);
result := true;
finally
dispose(ptmpPathName);
dispose(ptmpFileName);
end;
end;

2.简单封装了一个excel对象:
TExcelObj=class
private
_Application:Variant;
WorkBooks:Variant;
public
constructor Create(FileName:String);
procedure AppShow;
procedure OpenFile(FileName:String);
procedure Preview;
procedure Print;
end;
implementation
constructor TExcelObj.Create(FileName:String);
begin
try
_Application := CreateOleObject( 'Excel.Application' );
WorkBooks := _Application.WorkBooks.Open(FileName);
except on e:exception do
EMsgDlg( '调用Excel失败.'+#13+
'错误信息:'+e.Message+#13+
'处理建议:请确认Ms Excel在本机上已经正确安装.');
end;
end;

procedure TExcelObj.OpenFile(FileName: String);
begin
try
WorkBooks:=_Application.WorkBooks.Open(FileName);
except on e:exception do
EMsgDlg( '调用Excel失败.'+#13+
'错误信息:文件'+FileName+'不存在,'+e.Message+#13+
'处理建议:.');
end;
end;

procedure TExcelObj.Preview;
begin
if not VarIsNull(WorkBooks) then
try
_Application.ActiveSheet.PrintPreview;
except on e:exception do
EMsgDlg( '调用Excel失败.'+#13+
'错误信息:打印文件出错,'+e.Message+#13+
'处理建议:检查打印机是否正确安装');
end;
end;

procedure TExcelObj.Print;
begin
if not VarIsNull(WorkBooks) then
try
_Application.ActiveSheet.PrintOut;
except on e:exception do
EMsgDlg( '调用Excel失败.'+#13+
'错误信息:打印文件出错,'+e.Message+#13+
'处理建议:.检查打印机是否正确安装');
end;
end;

3.调用预览功能
var excelObj:TExcelObj;
begin
try
excelObj:= TExcelObj.Create(FileName);
excelObj.appshow;
excelObj.Preview;
finally
excelObj.Free;
end;
 
接受答案了.
 
后退
顶部