当前查询的数据是利用AppServer结构得到的, 并且在ListView中显示出来了
但我不知道怎么输出到报表中,请各位有经验的高手谈谈方法,要多少分就给先给50
但我不知道怎么输出到报表中,请各位有经验的高手谈谈方法,要多少分就给先给50
解决方案 »
- 请问这句定义是什么意思???
- MoveFileEX无法移动文件的问题,请大家帮忙看看
- Invalid Pointer operation,点击DLL中MDIChild窗体的菜单项后,引出的问题。
- 两个ADOQuery指向同一个数据库表,在一个中增加记录,另一个是否自动增加记录?
- 谁有TDock97?
- 有谁知道Delphi+SQLServer的项目是怎么发布的?
- 李维的演讲录音为什么不能播放?
- 代码大全中文电子版在4个月来近100位网友出色的志愿工作下终于诞生了 ! !
- 菜鸟问题,,,,主细表,用两个query怎样办呀?
- Delphi 10.2真机调试问题???
- 怎么把real转成string型
- 简单问题,关于路径的获取?
Procedure TMainForm.ExcelReport(var Office:Variant;DS:TDataSet;title:String);
var
sheet:Variant;
i,j,m,row,column:integer;
s:string;
bm:TbookMark;
begin
if Ds.Active = false then
Raise Exception.Create('生成报表时错误,数据表不在打开状态。执行查询或统计之后才能生成报表。');
if Ds.RecordCount = 0 then
Raise Exception.Create('生成报表失败。当前零条记录。');
try
Office:=CreateOleObject('Excel.Application');
Except
Raise Exception.Create('打开Excel时错误。报表功能需要安装Excel,如果已安装Excel则可能需要重新安装。'); end; bm:=Ds.GetBook ;
Try
Ds.DisableControls ;
Try
row:=Ds.RecordCount ;
Column:=Ds.FieldCount ; if not (Ds = Dm.Aqy) then
Office.visible:=true;
Office.WorkBooks.add;
Sheet:=Office.ActiveSheet;
j:=ord('a')+DS.FieldCount - 1 ;
s:='a1:'+Chr(j)+'1';
sheet.range[s].select;
Office.selection.merge;
Sheet.cells[1,1].Value:=Title;//'请在这里输入你的报表名称';
sheet.rows['1:1'].rowheight:=40;
Sheet.cells[1,1].font.bold:=true;
Sheet.cells[1,1].font.size:=16;
Sheet.cells[1,1].HorizontalAlignment:=xlCenter;
Sheet.cells[1,1].VerticalAlignment:=xlCenter;
//设置边框样式
s:='a2:'+chr(j)+inttostr(Row+2);
Sheet.range[s].select;
Office.Selection.NumberFormatLocal:='@';
Office.selection.Borders[xlDiagonalDown].LineStyle := xlNone;
Office.selection.Borders[xlDiagonalUp].LineStyle := xlNone;
Office.Selection.Borders[xlEdgeLeft].LineStyle := xlContinuous;
Office.Selection.Borders[xlEdgeLeft].Weight := xlThin;
Office.Selection.Borders[xlEdgeLeft].ColorIndex := xlAutomatic;
Office.Selection.Borders[xlEdgeTop].LineStyle := xlContinuous;
Office.Selection.Borders[xlEdgeTop].Weight :=xlThin ;
Office.Selection.Borders[xlEdgeTop].ColorIndex :=xlAutomatic ;
Office.Selection.Borders[xlEdgeBottom].LineStyle :=xlContinuous ;
Office.Selection.Borders[xlEdgeBottom].Weight :=xlThin ;
Office.Selection.Borders[xlEdgeBottom].ColorIndex :=xlAutomatic ;
Office.Selection.Borders[xlEdgeRight].LineStyle :=xlContinuous ;
Office.Selection.Borders[xlEdgeRight].Weight :=xlThin ;
Office.Selection.Borders[xlEdgeRight].ColorIndex :=xlAutomatic ;
Office.Selection.Borders[xlInsideVertical].LineStyle :=xlContinuous ;
Office.Selection.Borders[xlInsideVertical].Weight :=xlThin ;
Office.Selection.Borders[xlInsideVertical].ColorIndex :=xlAutomatic ;
Office.Selection.Borders[xlInsideHorizontal].LineStyle :=xlContinuous ;
Office.Selection.Borders[xlInsideHorizontal].Weight :=xlThin ;
Office.Selection.Borders[xlInsideHorizontal].ColorIndex :=xlAutomatic ; //设置货币,日期等特殊格式
for i:=0 to Ds.FieldCount - 1 do begin
Sheet.cells[2,i+1].value:=Ds.Fields[i].DisplayLabel ;
s:=Chr(ord('a')+i)+':'+Chr(ord('a')+i);
if Ds.Fields[i].FieldType = dtDateTime then
Sheet.Columns[s].NumberFormatLocal := 'yyyy-mm-dd';
end; j:=0;
Ds.First;
//开始填充数据
while not Ds.Eof do begin
j:=j+1;
m:=ord('a')+DS.FieldCount - 1 ;
s:='a'+inttostr(j+2)+':'+Chr(m)+inttostr(j+2);
sheet.range[s].Select;
for i:=0 to Column - 1 do begin
Sheet.cells[j+2,i+1].value:=Ds.Fields[i].value ;
end;
Ds.next;
end; //设置自动列宽
for i:=0 to Ds.FieldCount - 1 do begin
s:=Chr(ord('a')+i)+':'+Chr(ord('a')+i);
Sheet.Columns[s].EntireColumn.AutoFit;
end; { 页面设置,我的电脑没有打印机不能用 }
//Sheet.PageSetup.CenterFooter:='第 &P 页,共 &N 页';
//Sheet.PageSetup.RightFooter:='&D'; Sheet.cells[1,1].activate;
Application.ProcessMessages ;
Finally
Ds.GotoBook(bm);
Ds.FreeBook(bm);
end;
Finally
Ds.EnableControls ;
end;
end;