[Solved] Change images to original size & centered in cell

Discuss the spreadsheet application

[Solved] Change images to original size & centered in cell

Postby Nemesis » Thu Jul 23, 2020 12:24 pm

This is a "2part" question.

I've got a game-list, that I've imported to OpenOffice.
My problem is that the images isn't original sizes and not centred in the cells, they are "free floating"..

Is there anyway to modify them ALL, instead of one at a time?

I got 900 of them...

2. How do I center the image, I haven't found any center function..
Last edited by Nemesis on Fri Jul 24, 2020 7:40 am, edited 1 time in total.
Openoffice 4.1.6 on Windows 10
Nemesis
 
Posts: 15
Joined: Wed Jan 08, 2020 5:53 pm

Re: Change ALL images to original size & centered in cell

Postby Zizi64 » Thu Jul 23, 2020 1:05 pm

The images are not located inside a Cell, but they are located on an independent graphic Layer.

Trere are Macro examples, how to align pictures to a cell virtually.
viewtopic.php?f=9&t=34544
Tibor Kovacs, Hungary; LO6.1.6, 6.2.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-6.4.5;AOO4.1.7
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 9725
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Change ALL images to original size & centered in cell

Postby John_Ha » Thu Jul 23, 2020 4:02 pm

1. Use IrfanView to batch resize each image to the same pixel count so step 2 works.
2. Use IrfanView to create a vertical or horizontal panorama image of all 900 images. You now have a long strip of all 900 images.
3. Insert the panorama image and position as required. Set row height or column width to the image size so everything lines up immediately.

Doing 900 full size images will give a huge file - minimise the pixel count at step 1 so as to reduce the file size. It may help to do 100 images at a time for 9 files.

See [Tutorial] Some useful hints on using images.

Showing that a problem has been solved helps others searching so, if your problem is now solved, please view your first post in this thread and click the Edit button (top right in the post) and add [Solved] in front of the subject.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
John_Ha
Volunteer
 
Posts: 8206
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Change ALL images to original size & centered in cell

Postby Nemesis » Thu Jul 23, 2020 4:20 pm

Zizi64 wrote:...


That macro worked great thx.
Openoffice 4.1.6 on Windows 10
Nemesis
 
Posts: 15
Joined: Wed Jan 08, 2020 5:53 pm

Re: Change ALL images to original size & centered in cell

Postby Nemesis » Thu Jul 23, 2020 4:30 pm

John_Ha wrote:1. Use IrfanView to batch resize
..


The images in the cells are original 1.72x2.43 cm but are 0.93x1.29 in the cells.
To get one to the original size, I right-click on the image and select "Original Size"..
There must be a way to get the calc to fix all at once..

I tried making a macro, but the action wasn't recorded.

Making one long image isn't a solution, since then I can't sort the table..
Openoffice 4.1.6 on Windows 10
Nemesis
 
Posts: 15
Joined: Wed Jan 08, 2020 5:53 pm

Re: Change ALL images to original size & centered in cell

Postby Zizi64 » Thu Jul 23, 2020 5:55 pm

I tried making a macro, but the action wasn't recorded.


You must WRITE your macro (based on the API functions) if you want to work efficiently with the macros.
Tibor Kovacs, Hungary; LO6.1.6, 6.2.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-6.4.5;AOO4.1.7
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 9725
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Change ALL images to original size & centered in cell

Postby Nemesis » Thu Jul 23, 2020 6:12 pm

Zizi64 wrote:
I tried making a macro, but the action wasn't recorded.


You must WRITE your macro (based on the API functions) if you want to work efficiently with the macros.


I almost guessed that, that's why I tried to record one to see what to write. I have no idea how to get it to restore the images..
Openoffice 4.1.6 on Windows 10
Nemesis
 
Posts: 15
Joined: Wed Jan 08, 2020 5:53 pm

Re: Change ALL images to original size & centered in cell

Postby Zizi64 » Thu Jul 23, 2020 6:16 pm

viewtopic.php?f=9&t=34544

Check Charlie Young's macro code in the linked topic.
Tibor Kovacs, Hungary; LO6.1.6, 6.2.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-6.4.5;AOO4.1.7
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 9725
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Change ALL images to original size & centered in cell

Postby Nemesis » Thu Jul 23, 2020 6:58 pm

Zizi64 wrote:https://forum.openoffice.org/en/forum/viewtopic.php?f=9&t=34544

Check Charlie Young's macro code in the linked topic.


I've seen the code, but since I don't know the command to set the original size, and the code is above my understanding..
Openoffice 4.1.6 on Windows 10
Nemesis
 
Posts: 15
Joined: Wed Jan 08, 2020 5:53 pm

Re: Change ALL images to original size & centered in cell

Postby John_Ha » Thu Jul 23, 2020 7:48 pm

Nemesis wrote:I don't know the command to set the original size, and the code is above my understanding..

Extract content.xml from the .ods file and use a simple Regular Expression (see the tutorial) Find and Replace to change all sizes to what you want. One search will do all 900.

This is from a spreadsheet with two images. The first is reduced while the second is full size. svg:width="205.69mm" svg:height="292.24mm" sets the image size while svg:x="13.85mm" svg:y="124.92mm" sets the location of the image top left corner on the page.

Code: Select all   Expand viewCollapse view
<draw:frame draw:z-index="0" draw:name="Image 1" draw:style-name="gr1" draw:text-style-name="P1" svg:width="205.69mm" svg:height="292.24mm" svg:x="13.85mm" svg:y="124.92mm">
   <draw:image xlink:href="Pictures/1000000000000B200000085887098DB214D00F46.jpg" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad" loext:mime-type="image/jpeg">
      <text:p/>
   </draw:image>
</draw:frame>
<draw:frame draw:z-index="1" draw:name="Image 2" draw:style-name="gr1" draw:text-style-name="P1" svg:width="784.15mm" svg:height="567.36mm" svg:x="13.85mm" svg:y="451.59mm">
   <draw:image xlink:href="Pictures/1000000000000B200000085841BC8802082C6B82.jpg" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad" loext:mime-type="image/jpeg">
      <text:p/>
   </draw:image>
</draw:frame>


 Edit: Edit to correct statement.

Note that images in a spreadsheet are located relative to the page or cell location and are not anchored to cell content so images will not move if you sort data. But, if you anchor to a cell and add a row so the cell moves, the image will move. See the Calc Manual for details. 

First, find a way to do it manually which survives the sort. The automate that process. Do OLE objects get anchored to data? - check the Calc manual.

If you want images to move with data then it may be better to use a simple database with a report for the sorted data and associated images.
Last edited by John_Ha on Thu Jul 23, 2020 8:33 pm, edited 3 times in total.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
John_Ha
Volunteer
 
Posts: 8206
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Change ALL images to original size & centered in cell

Postby Nemesis » Thu Jul 23, 2020 8:15 pm

John_Ha wrote:
Nemesis wrote:I don't know the command to set the original size, and the code is above my understanding..

(see the tutorial)

Which one?
Openoffice 4.1.6 on Windows 10
Nemesis
 
Posts: 15
Joined: Wed Jan 08, 2020 5:53 pm

Re: Change ALL images to original size & centered in cell

Postby John_Ha » Thu Jul 23, 2020 8:17 pm

The comment applies to regular expressions. As you cannot understand macros do it a different way you can understand.

However, I think it is all moot. Does a sort move the images when the data moves? It does not move the images in my test file.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
John_Ha
Volunteer
 
Posts: 8206
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Change ALL images to original size & centered in cell

Postby Nemesis » Thu Jul 23, 2020 8:27 pm

John_Ha wrote:The comment applies to regular expressions. As you cannot understand macros do it a different way you can understand.

However, I think it is all moot. Does a sort move the images when the data moves? It does not move the images in my test file.


I meant you wrote "see the tutorial" but I don't know where it is (about extracting content.xml)

If the images are.. Wait a moment, you're right, wtf :x ?, If an image is anchored to a cell, it should move when the cell is moving..
.. At least in my pretty little world...
Openoffice 4.1.6 on Windows 10
Nemesis
 
Posts: 15
Joined: Wed Jan 08, 2020 5:53 pm

Re: Change ALL images to original size & centered in cell

Postby John_Ha » Thu Jul 23, 2020 8:35 pm

Nemesis wrote:If an image is anchored to a cell, it should move when the cell is moving..
.. At least in my pretty little world...

Learn the difference between a cell and the content within a cell.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
John_Ha
Volunteer
 
Posts: 8206
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Change ALL images to original size & centered in cell

Postby Nemesis » Thu Jul 23, 2020 8:55 pm

I did this way back with excel....
Is there no way to get the image to the cell-content, or use some external link?
Openoffice 4.1.6 on Windows 10
Nemesis
 
Posts: 15
Joined: Wed Jan 08, 2020 5:53 pm

Re: Change ALL images to original size & centered in cell

Postby Zizi64 » Thu Jul 23, 2020 9:20 pm

If an image is anchored to a cell, it should move when the cell is moving..


Cells never moving. The Cell A1 always will be located in the left-top corner. Only the cell contents moving.

When you delete the row 7, then the seventh row will not missed: only the contents will be deleted, and the contents of the other rows will be shifted "up".
Tibor Kovacs, Hungary; LO6.1.6, 6.2.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-6.4.5;AOO4.1.7
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 9725
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Change ALL images to original size & centered in cell

Postby Nemesis » Fri Jul 24, 2020 6:54 am

Well, let's get back to the original question, getting the images to original size..
Openoffice 4.1.6 on Windows 10
Nemesis
 
Posts: 15
Joined: Wed Jan 08, 2020 5:53 pm

Re: Change ALL images to original size & centered in cell

Postby Zizi64 » Fri Jul 24, 2020 7:19 am

Unfortunatelly the API command
Code: Select all   Expand viewCollapse view
.setPropertyToDefault

can not work with the string parameter "Size" nor "Height" nor "Width".


https://www.openoffice.org/api/docs/com ... State.html
Tibor Kovacs, Hungary; LO6.1.6, 6.2.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-6.4.5;AOO4.1.7
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 9725
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Change ALL images to original size & centered in cell

Postby Nemesis » Fri Jul 24, 2020 7:39 am

Gee.. never thought it would be this complicated.
I think I did all of this way back with Microsoft Excel in 07..

Well, I did at least get my question answered.
Thx for the help..
Openoffice 4.1.6 on Windows 10
Nemesis
 
Posts: 15
Joined: Wed Jan 08, 2020 5:53 pm

Re: [Solved] Change images to original size & centered in ce

Postby Zizi64 » Fri Jul 24, 2020 10:16 am

The solution is not in the command "setPropertyToDefault", but it is in the relation of the methods/properties
Code: Select all   Expand viewCollapse view
oItem.Graphic.Size100thMM.Width
oItem.Graphic.Size100thMM.Height

and the
Code: Select all   Expand viewCollapse view
oItem.Size.Width
oItem.Size.Height

The "oItem.Graphic.Size100thMM." contains the default size values of the image, and the "oItem.Size." contains the resized values (of the frame??).

Here is a sample file with the embedded macro code.
It works fine in my permanently installed LibreOffice 6.1.6 and in the AOO 4.1.5 portable version.

SetDefaultSize.ods
(12.57 KiB) Downloaded 32 times
Tibor Kovacs, Hungary; LO6.1.6, 6.2.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-6.4.5;AOO4.1.7
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 9725
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary


Return to Calc

Who is online

Users browsing this forum: Google [Bot], mike.stirton and 8 guests