Recent

Author Topic: Including Images - FPSpreadsheet  (Read 24549 times)

Mando

  • Full Member
  • ***
  • Posts: 181
Re: Including Images - FPSpreadsheet
« Reply #30 on: February 02, 2017, 12:15:35 pm »
Hi all.

I'm desperate.

I want to modify an excel xlxs file, inserting images in column 0 of all rows.
That file has several cols an rows with data. Col 0 for imagez, col is used to obtain the file name of the image.
I can read the file correctly, resize rows for write the images and save back the file. When i open the file with libreoffice calc , the images are distorted in height, also the height of them is growing with the row number. The height of image in row 0 its almost correct, in row 1 is a little bigger, in row 2 a little more bigger an so...the last image is enormous in height.

If i read the original file to obtain filenames of images and insert images in a new tworkbook, and save it, the result is ok. All images are correctly in size, position and scale. If i write somedata more, p.e. the filename of image in col 1, and save the new file, the images are wrong sized(in heigh) again.
I workarround playing whith y-scale, but its is relative to the height of the row  :o If scale value is greater than 0.12 the image is escaled, but if it is lower, then the image height is set to the scale value.
This behaviour is the same if the result file is .ods or .xlxs

Help, help....i dont understand  nothing.

Regards
« Last Edit: February 02, 2017, 01:10:03 pm by Mando »

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: Including Images - FPSpreadsheet
« Reply #31 on: February 02, 2017, 01:10:24 pm »
I suppose this issue is related to the mess I refered to above (http://forum.lazarus.freepascal.org/index.php/topic,31740.msg205631.html#msg205631), and I fear there's nothing I can do about it.

But let's give it a try. Please publish the code which you use to create the Excel file along with a few pictures which are to be embedded (pack lpi, lpr, lfm, pas and required image files into a shared zip and upload it under "Attachments and other options"). Without exactly knowing what you do there's no chance to help you.

Mando

  • Full Member
  • ***
  • Posts: 181
Re: Including Images - FPSpreadsheet
« Reply #32 on: February 02, 2017, 02:49:40 pm »
Ok, thanks.
I'm not at work right now.
Later i'll post the project and images.

Thanks again.

paweld

  • Hero Member
  • *****
  • Posts: 970
Re: Including Images - FPSpreadsheet
« Reply #33 on: April 11, 2017, 08:11:28 pm »
Hi WP,
i have that's same problem as Mando. Error  with a image y scale occurs when insert to one row image and text, but if a row contains only image, then image scale it's ok.
Example in attachment.
fpspreadsheet trunk, Lazarus trunk with fpc 3.0.2.
Best regards / Pozdrawiam
paweld

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: Including Images - FPSpreadsheet
« Reply #34 on: April 11, 2017, 10:02:34 pm »
Thanks for the demo. Fixed in r5832. If you don't use trunk you should open fpspreadsheet.pas and replace the function TsWorksheet.CalcRowHeight by this code:

Code: Pascal  [Select][+][-]
  1. function TsWorksheet.CalcRowHeight(ARow: Cardinal): Single;
  2. // In workbook units
  3. var
  4.   r: PRow;
  5. begin
  6.   r := FindRow(ARow);
  7.   if (r <> nil) and (r^.RowHeightType = rhtCustom) then
  8.     Result := GetRowHeight(ARow, FWorkbook.Units)
  9.   else
  10.   begin
  11.     Result := CalcAutoRowHeight(ARow);
  12.     if Result = 0 then
  13.       Result := GetRowHeight(ARow, FWorkbook.Units);
  14.   end;
  15. end;

P.S.
This is included in the new release version 1.8.2.
« Last Edit: April 11, 2017, 10:40:35 pm by wp »

paweld

  • Hero Member
  • *****
  • Posts: 970
Re: Including Images - FPSpreadsheet
« Reply #35 on: April 12, 2017, 09:50:55 am »
Thanks very much for quick reply. Now it's ok.
Best regards / Pozdrawiam
paweld

Moneo

  • Newbie
  • Posts: 3
Re: Including Images - FPSpreadsheet
« Reply #36 on: October 04, 2018, 01:05:18 pm »
I will revive the topic. How can I attach a hyperlink to an inserted image?

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: Including Images - FPSpreadsheet
« Reply #37 on: October 04, 2018, 01:26:42 pm »
This is not possible at the moment.

Moneo

  • Newbie
  • Posts: 3
Re: Including Images - FPSpreadsheet
« Reply #38 on: October 04, 2018, 01:55:45 pm »
How can i cheat with hyperlink & image?

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: Including Images - FPSpreadsheet
« Reply #39 on: October 04, 2018, 04:42:18 pm »
I added a hyperlink field to the TsImage record. Call the worksheet method AddHyperlinkToImage to add a hyperlink to an existing image. The image is identified by its index in the internal image list which is returned by WriteImage.

So far, only writing to ODS (LibreOffice) is supported.
[EDIT] Now, XLSX works too.

See this demo:
Code: Pascal  [Select][+][-]
  1. program demo_image;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   fpspreadsheet, fpstypes, fpsutils, fpsopendocument, xlsxooxml;
  7.  
  8. var
  9.   b: TsWorkbook;
  10.   sh: TsWorksheet;
  11.   img: Integer;
  12.  
  13. {$R *.res}
  14.  
  15. begin
  16.   b := TsWorkbook.Create;
  17.   try
  18.     sh := b.AddWorksheet('Test');
  19.     img := sh.WriteImage(0, 0, '..\..\images\components\TSWORKSHEETGRID_200.PNG');
  20.     sh.AddHyperlinkToImage(img, 'http://www.lazarus-ide.org/');
  21.     b.WriteToFile('test.ods', sfOpenDocument, true);
  22.     b.WriteToFile('test.xlsx', sfOOXML, true);
  23.   finally
  24.     b.Free;
  25.   end;
  26. end.  
« Last Edit: October 05, 2018, 06:32:33 pm by wp »

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: Including Images - FPSpreadsheet
« Reply #40 on: October 06, 2018, 01:26:55 pm »
As already noted in the previous post, the XLSX and ODS writers now can handle images with hyperlinks. The ODS format, also, can read such files. This is not possible for the XLSX format ATM which cannot even read images (the guy who invented their specification must have been a sadist...).

 

TinyPortal © 2005-2018