| View previous topic :: View next topic |
| Author |
Message |
rupike General User

Joined: 24 Jul 2007 Posts: 28
|
Posted: Tue Jul 31, 2007 2:06 am Post subject: Problem with removing all images from Calc Sheet. Help!!! |
|
|
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 |
|
 |
JerzyPiotr General User

Joined: 03 Sep 2005 Posts: 32 Location: Poland
|
Posted: Tue Jul 31, 2007 4:05 am Post subject: |
|
|
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 |
|
 |
rupike General User

Joined: 24 Jul 2007 Posts: 28
|
Posted: Tue Jul 31, 2007 6:40 am Post subject: |
|
|
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 |
|
 |
JerzyPiotr General User

Joined: 03 Sep 2005 Posts: 32 Location: Poland
|
Posted: Tue Jul 31, 2007 6:46 am Post subject: |
|
|
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 |
|
 |
rupike General User

Joined: 24 Jul 2007 Posts: 28
|
Posted: Tue Jul 31, 2007 9:23 pm Post subject: |
|
|
I have done this changes but the problem is not fixed.
Yevgeni |
|
| Back to top |
|
 |
JerzyPiotr General User

Joined: 03 Sep 2005 Posts: 32 Location: Poland
|
Posted: Wed Aug 01, 2007 12:03 am Post subject: |
|
|
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 |
|
 |
|