代码如下,数据库是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;