[Solved] Draw from cells
[Solved] Draw from cells
Hi,
Is it possible to make drawings sized as values in cells?
For example A1 is 10, A2 is 100
and AOO draws me a rectangle 10 / 100?
Thanks.
Is it possible to make drawings sized as values in cells?
For example A1 is 10, A2 is 100
and AOO draws me a rectangle 10 / 100?
Thanks.
Last edited by Hagar Delest on Tue Nov 27, 2012 11:04 am, edited 1 time in total.
Reason: tagged [Solved].
Reason: tagged [Solved].
OpenOffice 3.4.1 WINDOWS 7
Re: Draw from cells
Yes, it's called a graphrad wrote:Is it possible to make drawings sized as values in cells? ...

Possible, I guess, but you'd have to use a macro program to do it. OOo (directly) supports only graphics made by hand.
AOO4/LO5 • Linux • Fedora 23
Re: Draw from cells
That is what I thought, but it dose not work on "Size and positon" dialog window.
Any sugestioms?
Thanks.
Any sugestioms?
Thanks.
OpenOffice 3.4.1 WINDOWS 7
Re: Draw from cells
You can make a graph that adjusts to those input values, but I can't see that it is very useful. See the attached file.
What I did:
What I did:
- made a table with points in sequence to draw the rectangle
- made an x/y-graph based on that table and using lines only (no point marker symbols)
- removed the grid and the automatic scaling (so the specified dimensions would make a visible difference)
- adjusted size and scales so it's approximately 1:1 aspect ratio
- Attachments
-
- drawtest.ods
- (13.71 KiB) Downloaded 213 times
Apache OO 4.1.12 and LibreOffice 7.5, mostly on Ms Windows 10
Re: Draw from cells
Thank You for Your help I like it! I'll test if it works good for me.
BR
R
BR
R
OpenOffice 3.4.1 WINDOWS 7
- Charlie Young
- Volunteer
- Posts: 1559
- Joined: Fri May 14, 2010 1:07 am
Re: Draw from cells
A cell function can't modify cell contents except through its return value, but apparently there is no rule against it adding a shape to the DrawPage.
I keep thinking this whole concept is shaky somehow, but it is amusing to play with. Here is a function to draw a RectangleShape based on position, size, and color specified in cells. The position and sizes are in centimeters, but that's not terribly important. I'm just having the function return the name, but that's not important either. Note that the shapes can be moved around just by changing the cells. Formulas are entered in F1:F3 in the attached spreadsheet.
I think I'm going to play with some more options. One can imagine adding a rotation parameter, and there's nothing sacred about rectangles. I also think, if this is at all worthwhile, it should be done in Python or even c++, which I'm also going to try.
I keep thinking this whole concept is shaky somehow, but it is amusing to play with. Here is a function to draw a RectangleShape based on position, size, and color specified in cells. The position and sizes are in centimeters, but that's not terribly important. I'm just having the function return the name, but that's not important either. Note that the shapes can be moved around just by changing the cells. Formulas are entered in F1:F3 in the attached spreadsheet.
Code: Select all
Function DrawRectangle(x As Long, y As Long, w As Long, h As Long, Sheet As Integer, RectName As String, RectColor As Long) As String
Dim oDoc As Object
Dim oSheet As Object
Dim dPage As Object
Dim oRect As Object
Dim p As new com.sun.star.awt.Point
Dim s As new com.sun.star.awt.Size
Dim FoundIt As Boolean
Dim c As Long, i As Long
Dim v As Object
oDoc = ThisComponent
oSheet = oDoc.Sheets(Sheet)
dPage = oSheet.DrawPage
FoundIt = False
c = dPage.getCount()
i = c
Do While i > 0 and not FoundIt
v = dPage(i - 1)
if InStr(v.ShapeType, "RectangleShape") > 0 and v.Name = RectName then
dPage.remove(v)
FoundIt = True
else
i = i - 1
endif
Loop
oRect = oDoc.createInstance("com.sun.star.drawing.RectangleShape")
oRect.FillStyle = com.sun.star.drawing.FillStyle.SOLID
oRect.Name = RectName
dPage.add(oRect)
p.X = 1000 * X
p.Y = 1000 * Y
s.Width = 1000 * w
s.Height = 1000 * h
oRect.setSize(s)
oRect.setPosition(p)
oRect.FillColor = RectColor
DrawRectangle = RectName
End Function
- Attachments
-
- drawfromcells.ods
- Rectangle Drawing Function
- (10.94 KiB) Downloaded 230 times
Apache OpenOffice 4.1.1
Windows XP
Windows XP
Re: Draw from cells
It is very nice!
It would be great if size resolution could be 0,00cm now when You make 1,6cm You have 2cm and when You make 1,4 You have 1 etc.
Thank You!
It would be great if size resolution could be 0,00cm now when You make 1,6cm You have 2cm and when You make 1,4 You have 1 etc.
Thank You!
OpenOffice 3.4.1 WINDOWS 7
- Charlie Young
- Volunteer
- Posts: 1559
- Joined: Fri May 14, 2010 1:07 am
Re: Draw from cells
That is a consequence of my making the parameters Long instead of Double, and it's an easy change. The actual resolution is 1/100 mm, but that should be good enough. Here is the altered macro:rad wrote: It would be great if size resolution could be 0,00cm now when You make 1,6cm You have 2cm and when You make 1,4 You have 1 etc.
Thank You!
Code: Select all
Function DrawRectangle(x As Double,y As Double,w As Double, h As Double, Sheet As Integer, RectName As String, RectColor As Long) As String
Dim oDoc As Object
Dim oSheet As Object
Dim dPage As Object
Dim oRect As Object
Dim p As new com.sun.star.awt.Point
Dim s As new com.sun.star.awt.Size
Dim FoundIt As Boolean
Dim c As Long, i As Long
Dim v As Object
oDoc = ThisComponent
oSheet = oDoc.Sheets(Sheet)
dPage = oSheet.DrawPage
FoundIt = False
c = dPage.getCount()
i = c
Do While i > 0 and not FoundIt
v = dPage(i - 1)
if InStr(v.ShapeType, "RectangleShape") > 0 and v.Name = RectName then
dPage.remove(v)
FoundIt = True
else
i = i - 1
endif
Loop
oRect = oDoc.createInstance("com.sun.star.drawing.RectangleShape")
oRect.FillStyle = com.sun.star.drawing.FillStyle.SOLID
oRect.Name = RectName
dPage.add(oRect)
p.X = CLng(1000 * X)
p.Y = CLng(1000 * Y)
s.Width = CLng(1000 * w)
s.Height = CLng(1000 * h)
oRect.setSize(s)
oRect.setPosition(p)
oRect.FillColor = RectColor
DrawRectangle = RectName
End Function
Apache OpenOffice 4.1.1
Windows XP
Windows XP
- Charlie Young
- Volunteer
- Posts: 1559
- Joined: Fri May 14, 2010 1:07 am
Re: Draw from cells
I don't quite know what you have in mind here, could you explain further?rad wrote:Great!
Adding names would be useful.
I've been known to go way overboard, but then again...You have beer!
Apache OpenOffice 4.1.1
Windows XP
Windows XP
Re: Draw from cells
Normally You can give rectangle a name when You double click on it.
and also,
It would be nice if rectangles is not drawed when X or Y cell value is 0.
Some times it is necessary to go way overboard.
Thank You again for Your help.
and also,
It would be nice if rectangles is not drawed when X or Y cell value is 0.
Some times it is necessary to go way overboard.
Thank You again for Your help.
OpenOffice 3.4.1 WINDOWS 7
- Charlie Young
- Volunteer
- Posts: 1559
- Joined: Fri May 14, 2010 1:07 am
Re: Draw from cells
Relatively simple to do in a rudimentary form. With the text added though, one starts to think about all the formatting options.rad wrote:Normally You can give rectangle a name when You double click on it.
and also,
It would be nice if rectangles is not drawed when X or Y cell value is 0.
Some times it is necessary to go way overboard.
Thank You again for Your help.
But for starters, just add a sixth parameter for the "name," and assign it to the shape's string property in the macro:
Code: Select all
Function DrawRectangle(x As Double,y As Double,w As Double, h As Double, Sheet As Integer, RectName As String, RectColor As Long, RectText As String) As String
Dim oDoc As Object
Dim oSheet As Object
Dim dPage As Object
Dim oRect As Object
Dim p As new com.sun.star.awt.Point
Dim s As new com.sun.star.awt.Size
Dim FoundIt As Boolean
Dim c As Long, i As Long
Dim v As Object
oDoc = ThisComponent
oSheet = oDoc.Sheets(Sheet)
dPage = oSheet.DrawPage
FoundIt = False
c = dPage.getCount()
i = c
Do While i > 0 and not FoundIt
v = dPage(i - 1)
if InStr(v.ShapeType, "RectangleShape") > 0 and v.Name = RectName then
dPage.remove(v)
FoundIt = True
else
i = i - 1
endif
Loop
If X > 0 And Y > 0 Then
oRect = oDoc.createInstance("com.sun.star.drawing.RectangleShape")
oRect.FillStyle = com.sun.star.drawing.FillStyle.SOLID
oRect.Name = RectName
dPage.add(oRect)
p.X = CLng(1000 * X)
p.Y = CLng(1000 * Y)
s.Width = CLng(1000 * w)
s.Height = CLng(1000 * h)
oRect.setSize(s)
oRect.setPosition(p)
oRect.FillColor = RectColor
oRect.String = RectText
EndIf
DrawRectangle = RectName
End Function
Apache OpenOffice 4.1.1
Windows XP
Windows XP
- Charlie Young
- Volunteer
- Posts: 1559
- Joined: Fri May 14, 2010 1:07 am