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

How to locate and delete picture from spreadsheet

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
rebelxt
OOo Enthusiast
OOo Enthusiast


Joined: 10 Dec 2006
Posts: 114
Location: StLouis

PostPosted: Sun Feb 18, 2007 2:30 pm    Post subject: How to locate and delete picture from spreadsheet Reply with quote

The following routine will locate and delete all the pictures from one sheet in an Excel workbook. How can I accomplish the same thing in Calc?

Code:
Public Function DeletePictures(wSheet As String)
'Purpose: Delete all pictures associated with the specified worksheet.

'Arguments:
'      wSheet: Name of worksheet containing pictures
Dim n, c
n = Worksheets(wSheet).Shapes.Count
Do Until n = 0
    c = Worksheets(wSheet).Shapes(n).Name
    If Left(c, 8) = "Picture " Then
        Worksheets(wSheet).Shapes(n).Delete
    End If
    n = n - 1
Loop
End Function


Actually, all I really need to know is what statement(s) are required to locate the pictures, and the statement that will delete them.
Back to top
View user's profile Send private message
B Marcelly
Super User
Super User


Joined: 12 May 2004
Posts: 1453
Location: France

PostPosted: Mon Feb 19, 2007 2:57 am    Post subject: Re: How to locate and delete picture from spreadsheet Reply with quote

rebelxt wrote:
The following routine will locate and delete all the pictures from one sheet in an Excel workbook. How can I accomplish the same thing in Calc?
(...)
Actually, all I really need to know is what statement(s) are required to locate the pictures, and the statement that will delete them.

Your function is in fact a Sub. Equivalent for Calc
Code:
Sub DeletePictures(sheetName as string)
dim myCalc as object, mySheet as object, myPage as object
dim obj as object, x as long

myCalc = thisComponent
mySheet = myCalc.Sheets.getByName(sheetName)
myPage = mySheet.DrawPage
for x = myPage.Count -1 to 0 step -1
  obj = myPage(x)
  if obj.supportsService("com.sun.star.drawing.GraphicObjectShape")  then
    myPage.remove(obj)
    ' Issue 74651 : document does not set itself as modified
    myCalc.setModified(True) ' work-around for the bug
  end if
next
End Sub

I found Issue 74651 when creating this macro.
Back to top
View user's profile Send private message Visit poster's website
rebelxt
OOo Enthusiast
OOo Enthusiast


Joined: 10 Dec 2006
Posts: 114
Location: StLouis

PostPosted: Mon Feb 19, 2007 12:36 pm    Post subject: Reply with quote

Thanks, B, your subroutine worked just fine. I didn't have to change a thing. I wasn't expecting anyone to do the coding and debugging for me, but I'm sure that "issue 74651" thing would have caused me a lot of grief.

Thanks again,
rebelxt
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 Macros and API 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