Re: Delete table in cursor position

Andrew Douglas Pitonyak <[email protected]> Sun, 10 Jul 2011 22:32:26 -0400
Newsgroups gmane.comp.openoffice.devel.general
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--------------050106010400000100080505
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

You should reply to the list, not to me directly.

I did look at this, and there are problems with any solution that I 
tried. For example, first, I tried walking the text table anchor, but I 
repeatedly crashed LO when I tried that. I also found that performing a 
few sneaky things (such as looking at the anchor's text object and then 
creating a cursor at that text object failed when I had a cell that 
contained ONLY a text table (because creating a cursor in that cell did 
not leave any place for that cursor to be except for in the containing 
text table).

Next, I tried another sneaky thing such as simply disposing the text 
table and then checking to see if the view cursor was still in a text 
table. it looks like that approach may work, but I did not pursue it 
past a few very basic tests.

sub MainTable
   Dim oTable
   Dim oVC
   Dim sName$
   ovc = ThisComponent.getCurrentController().getViewCursor()
   Do While NOT IsNull (ovc.TextTable) AND NOT IsEmpty(ovc.TextTable)
     oTable = ovc.TextTable
     sName = oTable.Name
     oTable.dispose()
     'Print "removed " & sName
   Loop
End Sub


On 07/10/2011 11:25 AM, Shameera Rathnayaka wrote:
> thanks Andrew,
>
> this is the code in java its worked
>
>   // get text view cursor from the text document
>             XController xController = 
> xTextDocument.getCurrentController();
>             XTextViewCursorSupplier xCursorSup = 
> (XTextViewCursorSupplier) 
> UnoRuntime.queryInterface(XTextViewCursorSupplier.class, xController);
>             XTextViewCursor xViewCursor = xCursorSup.getViewCursor();
>             XPropertySet xCursorPropertySet = (XPropertySet) 
> UnoRuntime.queryInterface(XPropertySet.class, xViewCursor);
>             Object tab = xCursorPropertySet.getPropertyValue("TextTable");
>             XTextTable table = (XTextTable) 
> UnoRuntime.queryInterface(XTextTable.class, tab);
>             table.dispose();  // delete the table
> and now i want to duplicate the complex table, complex table mean it 
> has several tables inside it, even if the cursor inside the one of 
> it's child table, i want to duplicate the full complex table. for this 
> i want to select most outer table.
> can anybody help me with this
>
> *Thanks*
>
> On Sun, Jul 10, 2011 at 7:28 PM, Andrew Douglas Pitonyak 
> <[email protected] <mailto:[email protected]>> wrote:
>
>     On 07/09/2011 01:52 AM, Shameera Rathnayaka wrote:
>>     hi dev,
>>
>>     This is my problem i could delete all table in doc , but how can
>>     i delete table in cursor position which i dont know the name and
>>     index of that table.
>
>     I believe that the view cursor has a text table property that you
>     can check to see if the cursor is in a text table. This is how I
>     do it in Basic
>
>       Dim oVC : oVC = ThisComponent.getCurrentController().getViewCursor()
>       If Not IsNull(oVC.TextTable) Then
>         Print "In TextTable " & oVC.TextTable.Name
>     <http://oVC.TextTable.Name>
>       End If
>
>
>>
>>     here my code to delete all table in textRange but it delete all
>>     table in my doc, if you know please give me a help or point out
>>     some helpful links
>>
>>     XTextTable table=null;
>>             XText text = xTextDocument.getText();
>>             XTextRange textRange= text.getStart();
>>
>>             XEnumerationAccess xParaAccess = (XEnumerationAccess)
>>     UnoRuntime.queryInterface(XEnumerationAccess.class,
>>     textRange.getText());
>>             XEnumeration xParaEnum = xParaAccess.createEnumeration();
>>             while (xParaEnum.hasMoreElements()) {
>>                 try {
>>                     Object objElement = xParaEnum.nextElement();
>>                     XServiceInfo xInfo = (XServiceInfo)
>>     UnoRuntime.queryInterface(XServiceInfo.class, objElement);
>>                     if
>>     (xInfo.supportsService("com.sun.star.text.TextTable")) {
>>                         table = (XTextTable) UnoRuntime.queryInterface(
>>                            XTextTable.class,objElement);
>>                         table.dispose();
>>                     }
>>                 } catch
>>     (com.sun.star.container.NoSuchElementException ex) {
>>                    
>>     java.util.logging.Logger.getLogger(TableOparater.class.getName()).log(Level.SEVERE,
>>     null, ex);
>>                 } catch (WrappedTargetException ex) {
>>                    
>>     java.util.logging.Logger.getLogger(TableOparater.class.getName()).log(Level.SEVERE,
>>     null, ex);
>>                 }
>>         }
>>
>>     *thanks *
>>     -- 
>>     Shameera Rathnayaka
>>     Undergraduate
>>     Department of Computer Science and Engineering
>>     University of Moratuwa.
>>     Sri Lanka.
>>     T.P.  0719221454
>
>     -- 
>     Andrew Pitonyak
>     My Macro Document:http://www.pitonyak.org/AndrewMacro.odt
>     Info:http://www.pitonyak.org/oo.php
>
>
>
>
> -- 
> Shameera Rathnayaka
> Undergraduate
> Department of Computer Science and Engineering
> University of Moratuwa.
> Sri Lanka.
> T.P.  0719221454

-- 
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.odt
Info:  http://www.pitonyak.org/oo.php

-- 
-----------------------------------------------------------------
To unsubscribe send email to [email protected]
For additional commands send email to [email protected]
with Subject: help

--------------050106010400000100080505
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#ffffff" text="#000000">
    You should reply to the list, not to me directly.<br>
    <br>
    I did look at this, and there are problems with any solution that I
    tried. For example, first, I tried walking the text table anchor,
    but I repeatedly crashed LO when I tried that. I also found that
    performing a few sneaky things (such as looking at the anchor's text
    object and then creating a cursor at that text object failed when I
    had a cell that contained ONLY a text table (because creating a
    cursor in that cell did not leave any place for that cursor to be
    except for in the containing text table).<br>
    <br>
    Next, I tried another sneaky thing such as simply disposing the text
    table and then checking to see if the view cursor was still in a
    text table. it looks like that approach may work, but I did not
    pursue it past a few very basic tests.<br>
    <br>
    sub MainTable<br>
    &nbsp; Dim oTable<br>
    &nbsp; Dim oVC<br>
    &nbsp; Dim sName$<br>
    &nbsp; ovc = ThisComponent.getCurrentController().getViewCursor()<br>
    &nbsp; Do While NOT IsNull (ovc.TextTable) AND NOT IsEmpty(ovc.TextTable)<br>
    &nbsp;&nbsp;&nbsp; oTable = ovc.TextTable<br>
    &nbsp;&nbsp;&nbsp; sName = oTable.Name<br>
    &nbsp;&nbsp;&nbsp; oTable.dispose()<br>
    &nbsp;&nbsp;&nbsp; 'Print "removed " &amp; sName<br>
    &nbsp; Loop<br>
    End Sub<br>
    <br>
    <br>
    On 07/10/2011 11:25 AM, Shameera Rathnayaka wrote:
    <blockquote
cite="mid:CAJvLytqcwYsLvS2Ht9vbmi9_jfR1hXJ4+=eSOJ_QQu-HJrzBZQ@mail.gmail.com"
      type="cite">thanks Andrew,
      <div><br>
      </div>
      <div>this is the code in java its worked&nbsp;</div>
      <div><br>
      </div>
      <div>
        <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <font class="Apple-style-span" size="1">&nbsp; // get
            text view cursor from the text document</font></div>
        <div><font class="Apple-style-span" size="1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
            XController xController =
            xTextDocument.getCurrentController();</font></div>
        <div><font class="Apple-style-span" size="1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
            XTextViewCursorSupplier xCursorSup =
            (XTextViewCursorSupplier)
            UnoRuntime.queryInterface(XTextViewCursorSupplier.class,
            xController);</font></div>
        <div><font class="Apple-style-span" size="1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
            XTextViewCursor xViewCursor = xCursorSup.getViewCursor();</font></div>
        <div><font class="Apple-style-span" size="1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
            XPropertySet xCursorPropertySet = (XPropertySet)
            UnoRuntime.queryInterface(XPropertySet.class, xViewCursor);</font></div>
        <div><font class="Apple-style-span" size="1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Object
            tab = xCursorPropertySet.getPropertyValue("TextTable");</font></div>
        <div><font class="Apple-style-span" size="1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
            XTextTable table = (XTextTable)
            UnoRuntime.queryInterface(XTextTable.class, tab);</font></div>
        <div><font class="Apple-style-span" size="1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
            table.dispose();&nbsp; // delete the table &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</font></div>
        <div><font class="Apple-style-span" size="1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</font></div>
        <div>and now i want to duplicate the complex table, complex
          table mean it has several tables inside it, even if the cursor
          inside the one of it's child table, i want to duplicate the
          full complex table. for this i want to select most outer
          table.&nbsp;</div>
        <div>can anybody help me with this &nbsp;</div>
        <div><br>
        </div>
        <b>Thanks</b></div>
      <div><br>
        <div class="gmail_quote">On Sun, Jul 10, 2011 at 7:28 PM, Andrew
          Douglas Pitonyak <span dir="ltr">&lt;<a
              moz-do-not-send="true" href="mailto:[email protected]">[email protected]</a>&gt;</span>
          wrote:<br>
          <blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
            0.8ex; border-left: 1px solid rgb(204, 204, 204);
            padding-left: 1ex;">
            <div bgcolor="#ffffff" text="#000000">
              <div class="im"> On 07/09/2011 01:52 AM, Shameera
                Rathnayaka wrote:
                <blockquote type="cite">hi dev,
                  <div><br>
                  </div>
                  <div>This is my problem i could delete all table in
                    doc , but how can i delete table in cursor position
                    which i dont know the name and index of that table.</div>
                </blockquote>
                <br>
              </div>
              I believe that the view cursor has a text table property
              that you can check to see if the cursor is in a text
              table. This is how I do it in Basic<br>
              <br>
              &nbsp; Dim oVC : oVC =
              ThisComponent.getCurrentController().getViewCursor()<br>
              &nbsp; If Not IsNull(oVC.TextTable) Then<br>
              &nbsp;&nbsp;&nbsp; Print "In TextTable " &amp; <a moz-do-not-send="true"
                href="http://oVC.TextTable.Name" target="_blank">oVC.TextTable.Name</a><br>
              &nbsp; End If
              <div>
                <div class="h5"><br>
                  <br>
                  <blockquote type="cite">
                    <div><br>
                    </div>
                    <div>here my code to delete all table in textRange
                      but it delete all table in my doc, if you know
                      please give me a help or point out some helpful
                      links&nbsp;</div>
                    <div><br>
                    </div>
                    <div>
                      <div>XTextTable table=null;</div>
                      <div>&nbsp; &nbsp; &nbsp; &nbsp; XText text = xTextDocument.getText();</div>
                      <div>&nbsp; &nbsp; &nbsp; &nbsp; XTextRange textRange=
                        text.getStart();</div>
                      <div><br>
                      </div>
                      <div>&nbsp; &nbsp; &nbsp; &nbsp; XEnumerationAccess xParaAccess =
                        (XEnumerationAccess)
                        UnoRuntime.queryInterface(XEnumerationAccess.class,
                        textRange.getText());</div>
                      <div>&nbsp; &nbsp; &nbsp; &nbsp; XEnumeration xParaEnum =
                        xParaAccess.createEnumeration();</div>
                      <div>&nbsp; &nbsp; &nbsp; &nbsp; while (xParaEnum.hasMoreElements()) {</div>
                      <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try {</div>
                      <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Object objElement =
                        xParaEnum.nextElement();</div>
                      <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; XServiceInfo xInfo =
                        (XServiceInfo)
                        UnoRuntime.queryInterface(XServiceInfo.class,
                        objElement);</div>
                      <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if
                        (xInfo.supportsService("com.sun.star.text.TextTable"))
                        {</div>
                      <div> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; table = (XTextTable)
                        UnoRuntime.queryInterface(</div>
                      <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                        &nbsp;XTextTable.class,objElement);</div>
                      <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; table.dispose();</div>
                      <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div>
                      <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } catch
                        (com.sun.star.container.NoSuchElementException
                        ex) {</div>
                      <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                        java.util.logging.Logger.getLogger(TableOparater.class.getName()).log(Level.SEVERE,

                        null, ex);</div>
                      <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } catch (WrappedTargetException
                        ex) {</div>
                      <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                        java.util.logging.Logger.getLogger(TableOparater.class.getName()).log(Level.SEVERE,

                        null, ex);</div>
                      <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div>
                      <div>&nbsp; &nbsp; }</div>
                      <div><br>
                      </div>
                      <b>thanks&nbsp;</b><br>
                      -- <br>
                      <span style="font-family: comic sans
                        ms,sans-serif;">Shameera Rathnayaka</span><br
                        style="font-family: comic sans ms,sans-serif;">
                      <span style="font-family: comic sans
                        ms,sans-serif;">Undergraduate</span><br
                        style="font-family: comic sans ms,sans-serif;">
                      <span style="font-family: comic sans
                        ms,sans-serif;">Department of Computer Science
                        and Engineering</span><br style="font-family:
                        comic sans ms,sans-serif;">
                      <span style="font-family: comic sans
                        ms,sans-serif;">University of Moratuwa.</span><br
                        style="font-family: comic sans ms,sans-serif;">
                      <span style="font-family: comic sans
                        ms,sans-serif;">Sri Lanka.</span><br
                        style="font-family: comic sans ms,sans-serif;">
                      <span style="font-family: comic sans
                        ms,sans-serif;">T.P.&nbsp; 0719221454</span><br>
                    </div>
                  </blockquote>
                  <br>
                </div>
              </div>
              <pre cols="72">-- 
Andrew Pitonyak
My Macro Document: <a moz-do-not-send="true" href="http://www.pitonyak.org/AndrewMacro.odt" target="_blank">http://www.pitonyak.org/AndrewMacro.odt</a>
Info:  <a moz-do-not-send="true" href="http://www.pitonyak.org/oo.php" target="_blank">http://www.pitonyak.org/oo.php</a>
</pre>
            </div>
          </blockquote>
        </div>
        <br>
        <br clear="all">
        <br>
        -- <br>
        <span style="font-family: comic sans ms,sans-serif;">Shameera
          Rathnayaka</span><br style="font-family: comic sans
          ms,sans-serif;">
        <span style="font-family: comic sans ms,sans-serif;">Undergraduate</span><br
          style="font-family: comic sans ms,sans-serif;">
        <span style="font-family: comic sans ms,sans-serif;">Department
          of Computer Science and Engineering</span><br
          style="font-family: comic sans ms,sans-serif;">
        <span style="font-family: comic sans ms,sans-serif;">University
          of Moratuwa.</span><br style="font-family: comic sans
          ms,sans-serif;">
        <span style="font-family: comic sans ms,sans-serif;">Sri Lanka.</span><br
          style="font-family: comic sans ms,sans-serif;">
        <span style="font-family: comic sans ms,sans-serif;">T.P.&nbsp;
          0719221454</span><br>
      </div>
    </blockquote>
    <br>
    <pre class="moz-signature" cols="72">-- 
Andrew Pitonyak
My Macro Document: <a class="moz-txt-link-freetext" href="http://www.pitonyak.org/AndrewMacro.odt">http://www.pitonyak.org/AndrewMacro.odt</a>
Info:  <a class="moz-txt-link-freetext" href="http://www.pitonyak.org/oo.php">http://www.pitonyak.org/oo.php</a>
</pre>
  </body>
</html>

--------------050106010400000100080505--