Hiding Jpeg with cell

Discuss the spreadsheet application
Post Reply
lucaslu88
Posts: 4
Joined: Fri Apr 13, 2018 4:31 pm

Hiding Jpeg with cell

Post by lucaslu88 »

Is there any way to hide pictures along with cell?

Summary
I have created about 50 columns of list of items for products, each of them contains picture of the product,
When the product is not in used for that project, I will hide the column, however, the picture does not hide with it, even after I have anchored it to the cell.

Anyway, to hide the jpeg along with the cell?

Thanks
User avatar
Zizi64
Volunteer
Posts: 11361
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Hiding Jpeg with cell

Post by Zizi64 »

You can achieve this task with some macro programming:
Toggle images.ods
(99.64 KiB) Downloaded 176 times
Set the Macro security to "medium" before you open my sample file.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
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.
lucaslu88
Posts: 4
Joined: Fri Apr 13, 2018 4:31 pm

Re: Hiding Jpeg with cell

Post by lucaslu88 »

Thank you, after following the instructions above and setting the macro security to "Medium"
I reopen the file, it says
Quote:
"BASIC runtime error.
Object variable not set."

The picture doesn't hide either when i hide the cells,
User avatar
Zizi64
Volunteer
Posts: 11361
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Hiding Jpeg with cell

Post by Zizi64 »

I created ant tested the macro in my LibreOffice 5.4.6 version. It works well, without any error message.

And it works in my AOO 4.1.5 portable version AFTER acknowledgment of the error messages (four times).

Note: my macro is a sample only - how to hide/show a picture by a macro. The hide/show "Event" is the changing of the cell content in the column "A", but not the Hiding a column.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
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.
lucaslu88
Posts: 4
Joined: Fri Apr 13, 2018 4:31 pm

Re: Hiding Jpeg with cell

Post by lucaslu88 »

Ok, I got it..

I manage to hide the pictures by toggling the number 1 and 0
However, is it possible to fix the jpeg into a cell block and hide the fixed picture with the cell when you "hide column/row?
User avatar
Zizi64
Volunteer
Posts: 11361
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Hiding Jpeg with cell

Post by Zizi64 »

Use this macro to determine if a specific column is visible or not:

Code: Select all

Function IsVisible_col(ColName as string) as boolean
 Dim oDoc as object
 Dim oSheet as object
 Dim oColumns as object
 Dim oCol as object
 
 	oDoc = ThisComponent	
	oSheet=oDoc.getcurrentcontroller.activesheet
	oColumns = oSheet.getColumns()
	oCol = oColumns.getByName(ColName)
	
IsVisible_col = oCol.isVisible
end function
Usage:

=Function IsVisible_col("D")
the result will be 0/1 (false/true). Use the result as input parameter of the another function.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
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
Lupp
Volunteer
Posts: 3553
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Hiding Jpeg with cell

Post by Lupp »

I won't talk about OpnOfficeorg V 3.1 (as the OQ put in his signature). The behaviour of recent versions of AOO (as now the brand is) will be different, and there will be very few contributors to this forum still knowing anything about 3.1 for sure regarding such specific concerns.

I can tell that the current version 4.1.5 of AOO behaves inconsistent (imo) with this respect.

However, starting with version 4.1 (datestamped 2013-07-05 at latest) LibreOffice introduced a behaviour probably satisfying the OQ:
Hiding a column or a row the images anchored to a cell of that column/row get hidden if they were by width/height completely inside the hidden column/row.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
User avatar
Lupp
Volunteer
Posts: 3553
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Hiding Jpeg with cell

Post by Lupp »

I tried a bit more. Inserted images are among the shapes contained in the DrawPage of a sheet. To hide the shapes that are anchored to to hidden cells (column or row hidden) the ollowing code should work:

Code: Select all

Sub adjustShapeVisibilityToAnchorCellVisibility(Optional pSheet As Object)
doc0 = ThisComponent
If NOT doc0.SupportsService("com.sun.star.sheet.SpreadsheetDocument") Then Exit Sub
If IsMissing(pSheet) Then 
    pSheet = doc0.CurrentController.ActiveSheet
Else
    If NOT pSheet.SupportsService("com.sun.star.sheet.Spreadsheet") Then Exit Sub
End If
theDP  = pSheet.DrawPage
For k = 0 To theDP.Count - 1
    theShape = theDP(k)
    If theShape.Anchor.SupportsService("com.sun.star.sheet.SheetCell") Then
        theCell = theShape.Anchor
        If NOT theCell.Columns(0).IsVisible OR NOT theCell.Rows(0).IsVisible Then
            theShape.Visible = False
        Else
            theShape.Visible = True
        End If
    End If
Next k
End Sub
In LibreOffice (tested with 6.0.,3) images are handled inconsistently in a way I cannot even describe clearly if columns/rows get hidden where the images were anchored but not completely contained. The shown size is afflicted. Anyhow the changes seem to be reversible. The above code, however, works as expected.

We would surely prefer to get the action tríggered by hiding/showing columns/rows. I do not know a way to organise that. Dont know an appropriate listener type.

In AOO 4.1.5 hiding a column/row containing cells to which shapes are anchored moves the anchor. The test appied by the Sub can therefor not work. In addition the anchor is (of course) not moved back if the column/row is shown again. It's a bug.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
lucaslu88
Posts: 4
Joined: Fri Apr 13, 2018 4:31 pm

Re: Hiding Jpeg with cell

Post by lucaslu88 »

Lupp wrote:I won't talk about OpnOfficeorg V 3.1 (as the OQ put in his signature). The behaviour of recent versions of AOO (as now the brand is) will be different, and there will be very few contributors to this forum still knowing anything about 3.1 for sure regarding such specific concerns.

I can tell that the current version 4.1.5 of AOO behaves inconsistent (imo) with this respect.

However, starting with version 4.1 (datestamped 2013-07-05 at latest) LibreOffice introduced a behaviour probably satisfying the OQ:
Hiding a column or a row the images anchored to a cell of that column/row get hidden if they were by width/height completely inside the hidden column/row.
Sorry for the confusion, I am totally new here, and didn't know about the latest Version of Open office, but, yes I am using the latest AOO.
User avatar
Zizi64
Volunteer
Posts: 11361
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Hiding Jpeg with cell

Post by Zizi64 »

yes I am using the latest AOO.
Please update your signature in this forum. (User Control Panel: Profile TAB - Edit signature sub-TAB.)
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
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.
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Hiding Jpeg with cell

Post by John_Ha »

See [Tutorial] Some useful hints on using images for a discussion on how best to handle images in Writer. Much applies to Calc.
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.
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Hiding Jpeg with cell

Post by Villeroy »

A database could do what you want.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply