OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Problem with removing all images from Calc Sheet. Help!!!

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Calc
View previous topic :: View next topic  
Author Message
rupike
General User
General User


Joined: 24 Jul 2007
Posts: 28

PostPosted: Tue Jul 31, 2007 2:06 am    Post subject: Problem with removing all images from Calc Sheet. Help!!! Reply with quote

I want to remove all my images from the Calc sheet that has been previously added.
But my Calc is crashed.

Sub RemoveGraphicObject
Dim vSheet

vSheet = ThisComponent.Sheets(0)

REM Add the graphics object
Dim oDrawPages As Object
Dim oGraphic As Object

oDrawPage = vSheet.getDrawPage()

maxCount = oDrawPage.getCount

Dim arr(20) as Object

Dim k as Integer
Dim oShapeTry as Object
Dim oImage as Object
Dim i as Integer

i = 0

for k = maxCount - 1 to 0 Step -1
oShapeTry = oDrawPage.getByIndex(k)
if oShapeTry.getShapeType() = "com.sun.star.drawing.GraphicObjectShape" then
oImage = oShapeTry
arr(i) = oImage
i = i + 1
'oDrawPage.remove(oImage)
endif
next k

for i = 0 to UBound(arr)
if (arr(i) Is Nothing) = False then
oDrawPage.remove(arr(i))
arr(i) = Nothing
endif
next i

End Sub
Back to top
View user's profile Send private message
JerzyPiotr
General User
General User


Joined: 03 Sep 2005
Posts: 32
Location: Poland

PostPosted: Tue Jul 31, 2007 4:05 am    Post subject: Reply with quote

First of all insert an error handler at the beginning of your code (after the section with variable declaration). Turn on "Option Explicit" also at the beginning of the module codes.

On Local Error GoTo ERRORHANDLER

and just before the end

ERRORHANDLER:
If Err <> 0 Then MsgBox "Error " & err & ": " & _
error$ & chr(13) & "In Line: " & Erl & chr(13) & Now , 176

You should get somme information about what's wrong.
If you still have problems let me know.
Jerzy
Back to top
View user's profile Send private message
rupike
General User
General User


Joined: 24 Jul 2007
Posts: 28

PostPosted: Tue Jul 31, 2007 6:40 am    Post subject: Reply with quote

JerzyPiotr!

I have added the code that you recomend but the crash does not give me to a message error. Addetionally I want to write that if I add images, close Calc, reopen Calc and then call my mothod. All work fine.


Yevgeni
Back to top
View user's profile Send private message
JerzyPiotr
General User
General User


Joined: 03 Sep 2005
Posts: 32
Location: Poland

PostPosted: Tue Jul 31, 2007 6:46 am    Post subject: Reply with quote

You are right. Calc crushes without complain (don't ask me why).
To get ride of your images use
REM oDrawPage.remove(arr(i))
REM arr(i) = Nothing
arr(i).dispose()
in your code.
Regards
Jerzy
Back to top
View user's profile Send private message
rupike
General User
General User


Joined: 24 Jul 2007
Posts: 28

PostPosted: Tue Jul 31, 2007 9:23 pm    Post subject: Reply with quote

I have done this changes but the problem is not fixed.

Yevgeni
Back to top
View user's profile Send private message
JerzyPiotr
General User
General User


Joined: 03 Sep 2005
Posts: 32
Location: Poland

PostPosted: Wed Aug 01, 2007 12:03 am    Post subject: Reply with quote

Here is this code (1 line added, 2 lines outcommented).
Thes code works for me without problem on Linux Debian 4.0 and Windows 2000.
REM ***** BASIC *****
Option Explicit

Sub Main
RemoveGraphicObject
End Sub
'------------------------------------------------------------------------------
'
Sub RemoveGraphicObject
Dim vSheet
Dim oDrawPage
dim maxCount

On Local Error GoTo ErrorHandler
vSheet = ThisComponent.Sheets(0)

REM Add the graphics object
Dim oDrawPages As Object
Dim oGraphic As Object

oDrawPage = vSheet.getDrawPage()

maxCount = oDrawPage.getCount

Dim arr(20) as Object

Dim k as Integer
Dim oShapeTry as Object
Dim oImage as Object
Dim i as Integer

i = 0

for k = maxCount - 1 to 0 Step -1
oShapeTry = oDrawPage.getByIndex(k)
if oShapeTry.getShapeType() = "com.sun.star.drawing.GraphicObjectShape" then
oImage = oShapeTry
arr(i) = oImage
i = i + 1
'oDrawPage.remove(oImage)
endif
next k

for i = 0 to UBound(arr)
if (arr(i) Is Nothing) = False then
REM oDrawPage.remove(arr(i)) 'comment this line out
REM arr(i) = Nothing 'comment this line out
arr(i).dispose() 'added line
endif
next i

ErrorHandler:
If Err <> 0 Then MsgBox "Błąd " & err & ": " & _
error$ & chr(13) & "W linii: " & Erl & chr(13) & Now , 176
End Sub
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Calc All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group