如何将几张sql数据表(包括报表中的台头)倒成一张excel工作表(有相应的台头),给点源代码?谢谢
解决方案 »
- 什么是窗口句柄
- Delphi7+sqlserver2000,用adoQuery连接,在作Edit操作的时候,提交时会出现"无法为更新定位行,一些值可能已在最后一次读取后已更新"
- 一个调用DLL的奇怪问题
- 急求HSB(HSV)转换为RGB的解决办法
- 【转帖】来看2004对日货抵制的成果吧(日本调查机构统计)
- 关于串口通讯的问题!!!急呀。。。
- 在dbgrid中为什么备注型(或text型字段)的那一列总显示为(memo),其他字段类型对应的列正常。
- 如何动态生成一个图标?
- 请问哪能找到delphi6开发版中的所有VCL(组件)的中文介绍以及例子,多谢了。
- DELPHI7 关于COM+问题
- 急求一个问题!!!!!!!!!在线等待大家帮忙
- 急:一段希望生成EXE,在后台执行的程序,如何创建工程实现?
procedure TMaterialFrm.btnOutToExcelClick(Sender: TObject);
var
xlApp:TExcelApplication;
xlBook:TExcelWorkBook;
xlSheet:TExcelWorkSheet;
iRow:Double;
begin
if Application.MessageBox('是否确认将当前数据导出到Excel中?','程序提示',mb_yesno+mb_iconquestion)=idno then
exit;
xlApp:=TExcelApplication.Create(Self);
xlBook:=TExcelWorkBook.Create(Self);
xlSheet:=TExcelWorkSheet.Create(Self);
try
try
xlApp.ConnectKind:=ckNewInstance;
xlApp.Connect;
xlApp.Visible[0]:=True;
except
Application.MessageBox('没有安装Excel2000.','程序提示',mb_iconinformation);
exit;
end;
xlApp.WorkBooks.Add(EmptyParam,0);
xlBook.ConnectTo(xlApp.Workbooks[1]);
xlSheet.ConnectTo(xlBook.Worksheets[1] as _WorkSheet);
//打印和页面设置
//xlSheet.PageSetup.Orientation:=xlLandscape;
xlSheet.PageSetup.LeftMargin := xlApp.InchesToPoints(0.748031496062992);
xlSheet.PageSetup.RightMargin := xlApp.InchesToPoints(0.590551181102362);
xlSheet.PageSetup.TopMargin := xlApp.InchesToPoints(0.511811023622047);
xlSheet.PageSetup.BottomMargin := xlApp.InchesToPoints(0.78740157480315);
xlSheet.PageSetup.HeaderMargin := xlApp.InchesToPoints(0.511811023622047);
xlSheet.PageSetup.FooterMargin := xlApp.InchesToPoints(0.47244094488189);
xlSheet.PageSetup.PrintTitleRows := '$1:$2';
//页眉页脚
xlSheet.PageSetup.LeftFooter:= '日期:&D';
xlSheet.PageSetup.RightFooter:='第 &P 页,共 &N 页';
//列宽
xlSheet.Cells.Item[1,1].ColumnWidth:=14.13;
xlSheet.Cells.Item[1,2].ColumnWidth:=21.75;
xlSheet.Cells.Item[1,3].ColumnWidth:=6.88;
xlSheet.Cells.Item[1,4].ColumnWidth:=7.38;
xlSheet.Cells.Item[1,5].ColumnWidth:=6.25;
xlSheet.Cells.Item[1,6].ColumnWidth:=14.13;
//标题
xlSheet.Cells.Item[1,6]:='基本材料列表';
xlSheet.Cells.Item[1,6].Font.Size:=18;
xlSheet.Cells.Item[1,6].Font.name:='黑体';
xlSheet.Cells.Item[1,6].Font.Bold:=True;
xlSheet.Range[xlSheet.Cells.Item[1,1],xlSheet.Cells.Item[1,6]].Merge(EmptyParam);
xlSheet.Cells.Item[1,1].HorizontalAlignment:=xlCenter;
xlSheet.Cells.Item[1,1].VerticalAlignment:=xlTop;
xlSheet.Cells.Item[1,1].RowHeight:=27;
//表头
iRow:=2;
xlSheet.Cells.Item[iRow,1]:='材料编号';
xlSheet.Cells.Item[iRow,2]:='材料名称';
xlSheet.Cells.Item[iRow,3]:='单 位';
xlSheet.Cells.Item[iRow,4]:='类 别';
xlSheet.Cells.Item[iRow,5]:='颜 色';
xlSheet.Cells.Item[iRow,6]:='备 注';
xlSheet.Range[xlSheet.Cells.Item[iRow,1],xlSheet.Cells.Item[iRow,6]].Font.Bold:=True;
xlSheet.Range[xlSheet.Cells.Item[iRow,1],xlSheet.Cells.Item[iRow,6]].HorizontalAlignment:= xlCenter;
iRow:=iRow+1;
QryMaterial.DisableControls;
QryMaterial.First;
while not QryMaterial.Eof do
begin
xlSheet.Cells.Item[iRow,1]:=QryMaterial['MaterialId'];
xlSheet.Cells.Item[iRow,2]:=QryMaterial['MaterialName'];
xlSheet.Cells.Item[iRow,3]:=QryMaterial['MaterialUnit'];
xlSheet.Cells.Item[iRow,3].HorizontalAlignment:=xlCenter;
xlSheet.Cells.Item[iRow,4]:=QryMaterial['MaterialClass'];
xlSheet.Cells.Item[iRow,5].NumberFormatLocal := '@';
xlSheet.Cells.Item[iRow,5]:=QryMaterial['ColorId'];
xlSheet.Cells.Item[iRow,5].HorizontalAlignment:=xlCenter;
xlSheet.Cells.Item[iRow,6]:=QryMaterial['Res'];
QryMaterial.Next;
iRow:=iRow+1;
end;
QryMaterial.EnableControls;
xlSheet.Range[xlSheet.Cells.Item[2,1],xlSheet.Cells.Item[iRow-1,6]].Borders.LineStyle := xlContinuous;
xlApp.Disconnect;
finally
xlApp.Free;
xlBook.Free;
xlSheet.Free;
end;
end;