[Solved] Macro to remove frame around text

Creating a macro - Writing a Script - Using the API

[Solved] Macro to remove frame around text

Postby Tommy » Sun Jan 06, 2008 11:07 am

is there any way to delete a frame around text in an automated way (a keystroke, a menu item, a macro etc.) ?

i find myself very often in that situation after copy and paste text from web content.
the text is copied with a frame around it.

i have to remove it every time but the manual method is annoying.
(1. cut selected text insede the frame, 2. delete the empty frame, 3. paste the cut text in the frameless blank page).

i found a macro here: http://www.oooforum.org/forum/viewtopic ... move+frame
but it doesn't work

here's a screenshot that shows the frame around text that i wan to remove:
Image

thanks 4 your help
Last edited by Tommy on Wed Jul 30, 2008 7:03 pm, edited 1 time in total.
-----
using latest X-LibreOffice release, made portable by winPenPack.com
http://www.winpenpack.com/main/download.php?view.1354
User avatar
Tommy
 
Posts: 252
Joined: Sun Dec 23, 2007 2:44 pm

Re: macro to remove frame around text

Postby probe1 » Sat Jan 12, 2008 12:38 pm

I don't think this is a "frame" - seems to me, that it is the border of actual text width; see:

View>Text borders
(correct translation from my german OOo?)

Did this do the trick?

[posting from vacation: 8°52'55"N 98°16'1" E; actually 29°C]
Cheers
Winfried

DateTime2 extension: insert date, time or timestamp, formatted to your needs
User avatar
probe1
Volunteer
 
Posts: 277
Joined: Mon Oct 08, 2007 1:34 am
Location: Chonburi Thailand

Re: macro to remove frame around text

Postby Tommy » Tue Jan 15, 2008 2:54 pm

well, i'd like to have a macro tool to do that.

i found here some code
http://www.oooforum.org/forum/viewtopic.phtml?t=51300

unfortunately it doesn't work on my PC
-----
using latest X-LibreOffice release, made portable by winPenPack.com
http://www.winpenpack.com/main/download.php?view.1354
User avatar
Tommy
 
Posts: 252
Joined: Sun Dec 23, 2007 2:44 pm

Re: macro to remove frame around text

Postby Bill » Tue Jan 15, 2008 4:56 pm

The text in the screenshot is in a table. The "frame" is the table boundary. It is "removed" by converting the table to text.

How to remove frames?
Bill
Volunteer
 
Posts: 7220
Joined: Sat Nov 24, 2007 6:48 am

Re: macro to remove frame around text

Postby probe1 » Wed Jan 16, 2008 7:57 am

Tommy wrote:well, i'd like to have a macro tool to do that.

I started the macro recorder and got this:
Code: Select all   Expand viewCollapse view
sub textbegrenzung
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "ViewBounds"
args1(0).Value = false

dispatcher.executeDispatch(document, ".uno:ViewBounds", "", 0, args1())
end sub
Cheers
Winfried

DateTime2 extension: insert date, time or timestamp, formatted to your needs
User avatar
probe1
Volunteer
 
Posts: 277
Joined: Mon Oct 08, 2007 1:34 am
Location: Chonburi Thailand

Re: macro to remove frame around text

Postby Tommy » Sun Jun 08, 2008 4:02 pm

thanks probe1 and sorry for the late reply but i lost contact with this topic.

in the meantime i create this macro that does what i wanted:

Code: Select all   Expand viewCollapse view
sub RemoveTableBorders
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Delimiter"
args1(0).Value = CHR$(9)

dispatcher.executeDispatch(document, ".uno:ConvertTableToText", "", 0, args1())

rem ----------------------------------------------------------------------
rem dispatcher.executeDispatch(document, ".uno:ConvertTableToText", "", 0, Array())


end sub



however, there's a new problem, if i have more than 1 table in my document, how do i select all the tables in order to use the "RemoveBorder" macro on all of them?
-----
using latest X-LibreOffice release, made portable by winPenPack.com
http://www.winpenpack.com/main/download.php?view.1354
User avatar
Tommy
 
Posts: 252
Joined: Sun Dec 23, 2007 2:44 pm

Re: macro to remove frame around text

Postby Tommy » Wed Jul 30, 2008 7:03 pm

user DVezina posted this great macro on the OOo forum ( http://www.oooforum.org/forum/viewtopic ... 200#293200 ) which does exacty what i needed.

here's the code:

Code: Select all   Expand viewCollapse view
Sub manageText()

  dim dispatcher as object
  dim document as object
   
   dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
   document   = ThisComponent.CurrentController.Frame

   ' Tables   
   oTextTables = ThisComponent.getTextTables
   If NOT oTextTables.hasElements() Then Exit Sub
   For i = 0 To oTextTables.getCount() - 1

        ' Loop through tables
      oTable = oTextTables.getByIndex(i)

      oRows = oTable.getRows
      oColumns  = oTable.getColumns
      iColCount = oColumns.Count
      iRowCount = oRows.Count
       
      ' Loop through Cells
      For iRow = 0 to iRowCount - 1
         For iCol = 0 to iColCount - 1
            oCell = oTable.getCellByPosition(iCol, iRow)
               oEnum = oCell.createEnumeration()
               bTable = False
               Do While oEnum.hasMoreElements()
                     oElement = oEnum.nextElement()
                  If oElement.supportsService("com.sun.star.text.TextTable") Then
                     bTable= True
                  End If   
                  Loop             
            If oCell.getString() <> "" and bTable = False Then
               oCellText = oCell.getText()
               oTextCursor = oCellText.createTextCursor()
               oVC = ThisComponent.CurrentController.getViewCursor()
               oVC.gotoRange(oTextCursor.getEnd(), False) 
               oText = oVC.getText

               ' Copy Text to Clip Board
'               dispatcher.executeDispatch(document, ".uno:EndOfLineSel", "", 0, Array())
               dispatcher.executeDispatch(document, ".uno:EndOfDocumentSel", "", 0, Array())
                 dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())
                ' Go To End of Document
       
                dispatcher.executeDispatch(document, ".uno:GoToEndOfDoc", "", 0, Array())   
                dispatcher.executeDispatch(document, ".uno:GoToEndOfDoc", "", 0, Array())
             
                dispatcher.executeDispatch(document, ".uno:ResetAttributes", "", 0, Array())
                 
               ' Paste Text
                dispatcher.executeDispatch(document, ".uno:Paste", "", 0, Array())
               dispatcher.executeDispatch(document, ".uno:InsertPara", "", 0, Array())
             
            End If
         Next
      Next
       
   Next
   
   ' Once all the text is pasted, loop through tables and delete them.
   ' We need to do it this way because you have nested tables.
   
   oTextTables = ThisComponent.getTextTables
   lCount = oTextTables.getCount()
   Do While lCount <> 0
      oTable = oTextTables.getByIndex(0)
      oTable.dispose()
      oTextTables = ThisComponent.getTextTables
      lCount = oTextTables.getCount()
   Loop

End Sub
-----
using latest X-LibreOffice release, made portable by winPenPack.com
http://www.winpenpack.com/main/download.php?view.1354
User avatar
Tommy
 
Posts: 252
Joined: Sun Dec 23, 2007 2:44 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: Google [Bot] and 2 guests