Page 1 of 1

XLSReadWriteII4: Add same picture in multiple sheets

Posted: Tue Oct 26, 2010 6:07 am
by savagegod
Hi Lars,
I am facing a problem while adding same picture in multiple sheets. The picture is displayed only in first sheet, and next sheet onwards it is not displayed. What might be the reason? Is it possible to add same picture in multiple sheets? My source code is given below.

XLS.MSOPictures.Add.Filename := 'C:\ODF_Logo.PNG';

with XLS.Sheets[0].DrawingObjects.Pictures.Add do begin
PictureName := XLS.MSOPictures[0].Filename;
Col1 := seColumn.Value;
Row1 := seRow.Value;
Col2 := seColumn.Value + 3;
Row2 := seRow.Value + 8;
end;

with XLS.Sheets[1].DrawingObjects.Pictures.Add do begin
PictureName := XLS.MSOPictures[0].Filename;
Col1 := seColumn.Value;
Row1 := seRow.Value;
Col2 := seColumn.Value + 3;
Row2 := seRow.Value + 8;
end;

Please reply...........

Re: XLSReadWriteII4: Add same picture in multiple sheets

Posted: Mon Nov 08, 2010 6:37 am
by savagegod
Dear All,

Somebody please help me by answering to above question. Its seems production support of Axolot is not good. It seems I made a bad decision by purchasing XLSReadWriteII4.

Re: XLSReadWriteII4: Add same picture in multiple sheets

Posted: Tue Apr 26, 2011 1:00 pm
by LukeFitz
Don't know if this is still any use to you, but: the trick is to give the picture a different name for each sheet. You may wish to use a timestamp, or simply add a serial number; personally, I just add the sheet number to the filename.

Re: XLSReadWriteII4: Add same picture in multiple sheets

Posted: Thu Sep 08, 2011 7:26 pm
by BlueKnight
Changing the PictureName didn't work for me (it gave an error that the name was invalid).

However, I managed to work around the problem by using LoadFromFile for the TMSOPicture and then setting PictureId of the TDrwPicture, instead of setting the PictureName. To value of PictureId needs to be the same as TMSOPicture.Count *after* the TMSOPicture has been added (ie. index+1).

I hope this helps!

Re: XLSReadWriteII4: Add same picture in multiple sheets

Posted: Fri Sep 09, 2011 6:10 am
by LukeFitz
I beg your pardon: perhaps I wasn't terribly clear in my earlier post. I recommended changing, not PictureName, but the picture's filename. This multiplies the number of picture files, of course; but these renamed files will normally be in a temp directory, or can be controlled programmatically.

Re: XLSReadWriteII4: Add same picture in multiple sheets

Posted: Sat Sep 10, 2011 6:50 pm
by BlueKnight
I understand. In my case they are logo files, which are stored in one place only - so having multiple copies of the files doesn't work in this case.

Re: XLSReadWriteII4: Add same picture in multiple sheets

Posted: Wed Jan 23, 2013 11:13 pm
by Mojoala
I need help with this as well. And I see there is no answer yet.

Re: XLSReadWriteII4: Add same picture in multiple sheets

Posted: Thu Jan 24, 2013 3:08 am
by BlueKnight
Here's my work-around (with all error handling and other non-essential lines removed). Development was in C++Builder, but hopefully people can convert to Delphi, if required.

Code: Select all

TXLSReadWriteII4* xls = new TXLSReadWriteII4(NULL);
xls->Filename = fn;
xls->Version = xvExcel97;
if(!xls->Sheets->Count)
  xls->Sheets->Add();

TSheet* xlSht = xls->Sheets->Items[0];

TMSOPicture* msoPict = xls->MSOPictures->Add();
int picID = xls->MSOPictures->Count;
msoPict->LoadFromFile(ExtractFilePath(Application->ExeName) + "logo.jpg");

TDrwPicture* drwPict = xlSht->DrawingObjects->Pictures->Add();
drwPict->PictureId = picID;
drwPict->Col1 = 1;
drwPict->Row1 = 1;
drwPict->Col1Offset = 0.08;
drwPict->Row1Offset = 0.05;
drwPict->Col2 = 1;
drwPict->Row2 = 2;
drwPict->Col2Offset = 0.92;
drwPict->Row2Offset = 0.95;

xls->Write();

Re: XLSReadWriteII4: Add same picture in multiple sheets

Posted: Thu Jan 24, 2013 8:17 pm
by Mojoala
Now if some one can convert that to Either Delphi code or Visual Basic code....

Re: XLSReadWriteII4: Add same picture in multiple sheets

Posted: Thu Jan 24, 2013 8:42 pm
by Mojoala
I deleted the VB code since I can not verify it's workability, but one could easily create a VB Code from the Delphi code a lot easier then from the C++ code;

After using the online C++ to VB converter, it was easier to convert to Delphi from the VB code.

http://converter.telerik.com <------ tries to convert C++ to VB and vice-versa.

Re: XLSReadWriteII4: Add same picture in multiple sheets

Posted: Thu Jan 24, 2013 9:30 pm
by larsa
Hello

Did your VB code run well?

Re: XLSReadWriteII4: Add same picture in multiple sheets

Posted: Thu Jan 24, 2013 9:50 pm
by Mojoala
And here is the Delphi Code
FYI: Logo is a Global function elsewhere which returns the entire path and file name

Code: Select all

procedure LoadTheLogoNew(var aXLS: TXLSReadWriteII4; c1, r1, c2, r2, ts : Integer);
var xlSht : TSheet;
    msoPict : TMSOPicture;
    picID : integer;
    drwPict : TDrwPicture;
begin
  if UpperCase(ExtractFileExt(Logo)) = '.BMP' then
  begin
    if FileSizeFromFileName(Logo) >= 32000 then Exit;
  end;

  aXLS.Filename := Logo;

  xlSht := axls.Sheets.Items[ts];

  msoPict := aXLS.MSOPictures.Add;
  msoPict.LoadFromFile(Logo);

  drwPict := xlSht.DrawingObjects.Pictures.Add;
  drwPict.PictureId := ts + 1;
  drwPict.Col1 := c1;
  drwPict.Row1 := r1;
  drwPict.Col1Offset := 0.08
  drwPict.Row1Offset := 0.05
  drwPict.Col2 := c2;
  drwPict.Row2 := r2;
  drwPict.Col2Offset := 0.92
  drwPict.Row2Offset := 0.95
end;

Re: XLSReadWriteII4: Add same picture in multiple sheets

Posted: Thu Jan 24, 2013 9:52 pm
by Mojoala
I did not try the VB code. It was from an online translator.

Now the Delphi Code does work and I will be using it.

thanks!

Re: XLSReadWriteII4: Add same picture in multiple sheets

Posted: Thu Jan 24, 2013 9:53 pm
by BlueKnight
Yes, the C++ code did exactly what I needed it to do.