XLSReadWriteII4: Add same picture in multiple sheets

Questions and answers on how to use XLSReadWriteII 3/4/5.
Post Reply
savagegod
Posts: 2
Joined: Wed Apr 28, 2010 3:12 pm

XLSReadWriteII4: Add same picture in multiple sheets

Post 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...........
savagegod
Posts: 2
Joined: Wed Apr 28, 2010 3:12 pm

Re: XLSReadWriteII4: Add same picture in multiple sheets

Post 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.
LukeFitz
Posts: 3
Joined: Mon May 05, 2008 10:20 am

Re: XLSReadWriteII4: Add same picture in multiple sheets

Post 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.
BlueKnight
Posts: 8
Joined: Sun Jun 20, 2004 1:40 pm
Location: New Zealand
Contact:

Re: XLSReadWriteII4: Add same picture in multiple sheets

Post 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!
LukeFitz
Posts: 3
Joined: Mon May 05, 2008 10:20 am

Re: XLSReadWriteII4: Add same picture in multiple sheets

Post 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.
BlueKnight
Posts: 8
Joined: Sun Jun 20, 2004 1:40 pm
Location: New Zealand
Contact:

Re: XLSReadWriteII4: Add same picture in multiple sheets

Post 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.
Mojoala
Posts: 19
Joined: Wed Feb 29, 2012 5:54 pm

Re: XLSReadWriteII4: Add same picture in multiple sheets

Post by Mojoala »

I need help with this as well. And I see there is no answer yet.
BlueKnight
Posts: 8
Joined: Sun Jun 20, 2004 1:40 pm
Location: New Zealand
Contact:

Re: XLSReadWriteII4: Add same picture in multiple sheets

Post 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();
Mojoala
Posts: 19
Joined: Wed Feb 29, 2012 5:54 pm

Re: XLSReadWriteII4: Add same picture in multiple sheets

Post by Mojoala »

Now if some one can convert that to Either Delphi code or Visual Basic code....
Mojoala
Posts: 19
Joined: Wed Feb 29, 2012 5:54 pm

Re: XLSReadWriteII4: Add same picture in multiple sheets

Post 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.
Last edited by Mojoala on Thu Jan 24, 2013 10:01 pm, edited 3 times in total.
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: XLSReadWriteII4: Add same picture in multiple sheets

Post by larsa »

Hello

Did your VB code run well?
Lars Arvidsson, Axolot Data
Mojoala
Posts: 19
Joined: Wed Feb 29, 2012 5:54 pm

Re: XLSReadWriteII4: Add same picture in multiple sheets

Post 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;
Last edited by Mojoala on Thu Jan 24, 2013 10:54 pm, edited 1 time in total.
Mojoala
Posts: 19
Joined: Wed Feb 29, 2012 5:54 pm

Re: XLSReadWriteII4: Add same picture in multiple sheets

Post 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!
Last edited by Mojoala on Thu Jan 24, 2013 9:59 pm, edited 1 time in total.
BlueKnight
Posts: 8
Joined: Sun Jun 20, 2004 1:40 pm
Location: New Zealand
Contact:

Re: XLSReadWriteII4: Add same picture in multiple sheets

Post by BlueKnight »

Yes, the C++ code did exactly what I needed it to do.
Post Reply