Using DropMaster to Drag & Drop Excel Data?

Support forum for our inter-application drag-n-drop components.

Using DropMaster to Drag & Drop Excel Data?

Postby stevemaughan » Tue Oct 29, 2013 7:18 pm

I'm trying to use DropMaster to handle dragging data into my app from Excel. I'm using FlexCel as the Excel Biff8 parsing engine. It works well when I do a simple copy / paste (see code below - DM is not needed for this task). However, I'm having difficulty getting the drag and drop to work with DropMaster.

I've using DMTextTarget and setting the AcceptTExtFormat to dtfCustom. I can test to see if the format is available but I don't seem to be able to get the handle of the data (or access to the data in a stream). It looks as if DataObject is the method to use but I've trawled the demos and cannot find anything which I can use. The help file says DataObject is "Intended for advanced implementation".

Any help or pointer would be appreciated!

Thanks,

Steve

Code: Select all
procedure PasteFromBiff8(const Xls: TExcelFile; const Row, Col: integer);
var
  MyHandle: THandle;
  BiffPtr: pointer;
  BiffSize: Cardinal;
  MemStream: TMemoryStream;
begin
  ClipBoard.Open;
  try
    MyHandle := Clipboard.GetAsHandle(RegisterClipboardFormat('Biff8'));
    BiffPtr := GlobalLock(MyHandle);
    try
      BiffSize := GlobalSize(MyHandle);
      MemStream := TMemoryStream.Create;
      try
        MemStream.Write(BiffPtr^, BiffSize);
        MemStream.Position := 0;
        Xls.PasteFromXlsClipboardFormat(Row, Col, TFlxInsertMode.NoneDown, MemStream);

      finally
        FreeAndNil(MemStream);
      end; //finally
    finally
      GlobalUnlock(MyHandle);
    end;
  finally
    Clipboard.Close;
  end;
end;
stevemaughan
 
Posts: 2
Joined:
Mon Oct 28, 2013 5:19 pm

Re: Using DropMaster to Drag & Drop Excel Data?

Postby DropMaster » Tue Oct 29, 2013 7:29 pm

It should be something like:

Code: Select all
uses
   DMUtil;
...
var
   s: AnsiString;
...
s := DataObjGetFormat(DMTextTarget1.DataObject, 'Biff8');


s is now an AnsiString whose bytes are the bytes of the binary format you wanted. You can just copy them to your BIFF structure (I guess by writing them to a stream, same as you did in your example).

Hope this helps.
_________________________
DropMaster Support
DropMaster
 
Posts: 23
Joined:
Fri Apr 15, 2011 6:32 am

Re: Using DropMaster to Drag & Drop Excel Data?

Postby stevemaughan » Tue Oct 29, 2013 8:11 pm

Great - it works perfectly!

For anyone who is interested here's a link to a simple project which show the drag-n-drop functionality from Excel (Delphi XE4).

https://www.dropbox.com/s/n571w5cu8ssgbv2/ExcelDragDrop.zip

Steve
stevemaughan
 
Posts: 2
Joined:
Mon Oct 28, 2013 5:19 pm


Return to DropMaster

Who is online

Users browsing this forum: No registered users and 1 guest