代码如下,数据库是SQL,我已可以将每条数据导出,但导出图片时重叠在一起了,而没有按行排序。
procedure TPBProduct_frm.StoreToExcel;
var
data: TADODataSet;
ExcelApp, Ra:Variant;
row: Integer;
MyFormat:Word;
AData:THandle; //临时句柄变量。
APalette:HPALETTE; //临时变量。
Stream1:TMemoryStream;//TBlobStream
xx:TJpegImage;
begin
if not InitExcel(ExcelApp) then
exit;
data := TADODataSet.Create(nil);
data.Connection := SBDataMode.AdoConnection;
try
data.CommandText := 'select * from TPB_Product';
data.Open;
with TADODataSet.Create(nil) do
begin
Connection := SBDataMode.AdoConnection;
CommandText := 'select ProductNo, sum(FPrice) as sNum from TPB_Product group by ProductNo';
Open;
row := 1;
ExcelApp.Rows[row].RowHeight := 40;
Ra := ExcelApp.Range[ExcelApp.Cells[row, 1], ExcelApp.Cells[row, 7]];
Ra.font.size := 18;
Ra.font.Bold := true;
Ra.MergeCells := true;
ExcelApp.Cells[row, 1] := '部件库存情况表';
inc(row);
Ra := ExcelApp.Range[ExcelApp.Cells[row, 1], ExcelApp.Cells[row, 8]];
Ra.font.size := 10;
Ra.MergeCells := true;
ExcelApp.Cells[row, 1] := FormatDateTime('yyyy/mm/dd', Now);
inc(row);
ExcelApp.Cells[row, 1] := '部件编号';
ExcelApp.Cells[row, 2] := '部件名称';
ExcelApp.Columns[2].ColumnWidth := 15;
ExcelApp.Cells[row, 3] := '单位';
ExcelApp.Columns[3].ColumnWidth := 4;
ExcelApp.Cells[row, 4] := '型号规格';
ExcelApp.Columns[4].ColumnWidth := 20;
ExcelApp.Cells[row, 5] := '部件单价';
ExcelApp.Cells[row, 6] := '库存数量';
ExcelApp.Cells[row, 7] := '库存金额';
ExcelApp.Cells[row, 8] :='图片' ;
while not Eof do
begin
if data.Locate('ProductNo', FieldByName('ProductNo').AsString, []) then
begin
inc(row);
ExcelApp.Cells[row, 1] := FieldByName('ProductNo').AsString;
ExcelApp.Cells[row, 2] := data.FieldByName('EName').AsString;
ExcelApp.Cells[row, 3] := data.FieldByName('UnitId').AsString;
ExcelApp.Cells[row, 4] := data.FieldByName('PrductType').AsString;
ExcelApp.Cells[row, 5] := data.FieldByName('FactoryItemNo').AsString;
ExcelApp.Cells[row, 6] := data.FieldByName('CustEng').AsString;
ExcelApp.Cells[row, 7] := data.FieldByName('CName').AsString;
// ExcelApp.Cells[row, 8] :='' ;
//下面代码是将图片导出,可以导出,但重叠在['H4:,'I4']位置,如何让他按行显示,显示。
Stream1:= TMemoryStream.Create;
TBlobField(data.FieldByName('pictrue')).SaveToStream(Stream1);
Stream1.Position :=0;
xx:=TJpegImage.Create ;
xx.LoadFromStream(Stream1);
xx.SaveToClipboardFormat(MyFormat,AData,APalette);
ClipBoard.SetAsHandle(MyFormat, AData);
ExcelApp.ActiveSheet.Range['H4','I4'].select;//myworksheet1是当前活动的sheet页
ExcelApp.ActiveSheet.paste;
end;
Next;
Show;
end;
ExcelApp.Cells[row + 1, 2] := '合计';
ExcelApp.Cells[row+1,8]:='大计';
Free;
end;
finally
data.Free;
ExcelApp.ScreenUpdating := true;
end;
end;
function TPBProduct_frm.InitExcel(var excel: Variant): Boolean;
begin
try
excel := CreateOleObject('Excel.Application');
except
result := false;
ShowMessage('调用Excel出错!');
exit;
end;
excel.WorkBooks.Add;
excel.WorkSheets[1].Activate;
excel.Visible := true;
excel.ScreenUpdating := false;
excel.Rows.RowHeight := 18;
excel.ActiveSheet.PageSetup.PrintGridLines := false;
result := true;
end;
procedure TPBProduct_frm.StoreToExcel;
var
data: TADODataSet;
ExcelApp, Ra:Variant;
row: Integer;
MyFormat:Word;
AData:THandle; //临时句柄变量。
APalette:HPALETTE; //临时变量。
Stream1:TMemoryStream;//TBlobStream
xx:TJpegImage;
begin
if not InitExcel(ExcelApp) then
exit;
data := TADODataSet.Create(nil);
data.Connection := SBDataMode.AdoConnection;
try
data.CommandText := 'select * from TPB_Product';
data.Open;
with TADODataSet.Create(nil) do
begin
Connection := SBDataMode.AdoConnection;
CommandText := 'select ProductNo, sum(FPrice) as sNum from TPB_Product group by ProductNo';
Open;
row := 1;
ExcelApp.Rows[row].RowHeight := 40;
Ra := ExcelApp.Range[ExcelApp.Cells[row, 1], ExcelApp.Cells[row, 7]];
Ra.font.size := 18;
Ra.font.Bold := true;
Ra.MergeCells := true;
ExcelApp.Cells[row, 1] := '部件库存情况表';
inc(row);
Ra := ExcelApp.Range[ExcelApp.Cells[row, 1], ExcelApp.Cells[row, 8]];
Ra.font.size := 10;
Ra.MergeCells := true;
ExcelApp.Cells[row, 1] := FormatDateTime('yyyy/mm/dd', Now);
inc(row);
ExcelApp.Cells[row, 1] := '部件编号';
ExcelApp.Cells[row, 2] := '部件名称';
ExcelApp.Columns[2].ColumnWidth := 15;
ExcelApp.Cells[row, 3] := '单位';
ExcelApp.Columns[3].ColumnWidth := 4;
ExcelApp.Cells[row, 4] := '型号规格';
ExcelApp.Columns[4].ColumnWidth := 20;
ExcelApp.Cells[row, 5] := '部件单价';
ExcelApp.Cells[row, 6] := '库存数量';
ExcelApp.Cells[row, 7] := '库存金额';
ExcelApp.Cells[row, 8] :='图片' ;
while not Eof do
begin
if data.Locate('ProductNo', FieldByName('ProductNo').AsString, []) then
begin
inc(row);
ExcelApp.Cells[row, 1] := FieldByName('ProductNo').AsString;
ExcelApp.Cells[row, 2] := data.FieldByName('EName').AsString;
ExcelApp.Cells[row, 3] := data.FieldByName('UnitId').AsString;
ExcelApp.Cells[row, 4] := data.FieldByName('PrductType').AsString;
ExcelApp.Cells[row, 5] := data.FieldByName('FactoryItemNo').AsString;
ExcelApp.Cells[row, 6] := data.FieldByName('CustEng').AsString;
ExcelApp.Cells[row, 7] := data.FieldByName('CName').AsString;
// ExcelApp.Cells[row, 8] :='' ;
//下面代码是将图片导出,可以导出,但重叠在['H4:,'I4']位置,如何让他按行显示,显示。
Stream1:= TMemoryStream.Create;
TBlobField(data.FieldByName('pictrue')).SaveToStream(Stream1);
Stream1.Position :=0;
xx:=TJpegImage.Create ;
xx.LoadFromStream(Stream1);
xx.SaveToClipboardFormat(MyFormat,AData,APalette);
ClipBoard.SetAsHandle(MyFormat, AData);
ExcelApp.ActiveSheet.Range['H4','I4'].select;//myworksheet1是当前活动的sheet页
ExcelApp.ActiveSheet.paste;
end;
Next;
Show;
end;
ExcelApp.Cells[row + 1, 2] := '合计';
ExcelApp.Cells[row+1,8]:='大计';
Free;
end;
finally
data.Free;
ExcelApp.ScreenUpdating := true;
end;
end;
function TPBProduct_frm.InitExcel(var excel: Variant): Boolean;
begin
try
excel := CreateOleObject('Excel.Application');
except
result := false;
ShowMessage('调用Excel出错!');
exit;
end;
excel.WorkBooks.Add;
excel.WorkSheets[1].Activate;
excel.Visible := true;
excel.ScreenUpdating := false;
excel.Rows.RowHeight := 18;
excel.ActiveSheet.PageSetup.PrintGridLines := false;
result := true;
end;
解决方案 »
- delphi treeview节点问题
- 帮忙解释一下createprocess,createprocessA,createprocessW的区别
- 求助,Access 导入 SQL
- 怎样让程序暂停几秒后再执行?
- 用ActiveX可以实现把Word的强大的文字功能集成到IE中吗? 若有实例,愿给1000分赠送!
- 请教我下面的SQL语句,为何说我这个字段执行的时候没有参数,请指教。
- 谁能具体讲讲handle的意义和用法
- 客户端和服务器端用Socket发送和接收数据,但是服务器上有时会接收不到
- 有一个问题,是关于TQuery的FieldValues属性的,哪位高手帮忙解决一下?
- 在serversocket中如何用IP地址实现消息转发?急
- DLl调用失败-应用程序配置错误
- 将数据从access导入sqlserver的问题
改为
ExcelApp.ActiveSheet.range[ExcelApp.ActiveSheet.Cells[8,1], ExcelApp.ActiveSheet.Cells[8,row]]].select;
ExcelApp.ActiveSheet.range[ExcelApp.ActiveSheet.Cells[row,8], ExcelApp.ActiveSheet.Cells[row,8]].select;\
就行了,非常感谢,de410.