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

Copy and paste of tables in writer documents using Java

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
hanland
General User
General User


Joined: 01 Jul 2009
Posts: 6

PostPosted: Thu Nov 19, 2009 2:47 am    Post subject: Copy and paste of tables in writer documents using Java Reply with quote

Hi,

could anyone help out with this one? There are one or two threads regarding this, none of which provide a complete solution. I have tried using the info from these but nothing seems to work.

I have a template with a table in it. The table has to be copied n times and populated. The code I have runs, but creates no new tables???


Regards

/Dominic

Code:

      public void copy(XComponent xComp, XTextTable iTextTable) {

         try {
            XModel xModel = QI.XModel(xComp);
            XController iController = xModel.getCurrentController();

            
            XSelectionSupplier iSelectionSupplier = QI.XSelectionSupplier(iController);
            
            String [] arrCellNames = iTextTable.getCellNames();
            XTextTableCursor xTextTableCursor = iTextTable.createCursorByCellName(arrCellNames[0]);
            xTextTableCursor.gotoCellByName(arrCellNames[arrCellNames.length - 1], true);
            XCellRange xTableCellRange = QI.XCellRange(iTextTable);
            XCellRange xCellRange = xTableCellRange.getCellRangeByName(xTextTableCursor.getRangeName());
            iSelectionSupplier.select(xCellRange);

            XTextViewCursorSupplier iTextViewCursorSupplier = QI.XTextViewCursorSupplier(iController);
            XTextViewCursor iTextViewCursor = iTextViewCursorSupplier.getViewCursor();
            iTextViewCursor.gotoEnd(true);
            iTextViewCursor.gotoEnd(true);

            XTransferableSupplier iTransferableSupplier = QI.XTransferableSupplier(iController);
            XTransferable iTransferable = iTransferableSupplier.getTransferable();
            
            for (int i=0; i<3; i++) {
               iTextViewCursor.gotoEnd(true);
               iTransferableSupplier.insertTransferable(iTransferable);
            }
            
         } catch (Exception e) {
            throw new RuntimeException(e);
         }
      }
Back to top
View user's profile Send private message
JohnV
Administrator
Administrator


Joined: 07 Mar 2003
Posts: 9183
Location: Lexinton, Kentucky, USA

PostPosted: Thu Nov 19, 2009 12:04 pm    Post subject: Reply with quote

I can't help you with Java but here's some Basic code that may help. The Copy & Paste subs are basically just recorded.



Code:
Sub CopyTable
oDoc = ThisComponent
oVC = oDoc.CurrentController.getViewCursor
oTextTables = oDoc.getTextTables
Table = oTextTables.getByName("Table1")
oCell = Table.getCellByPosition(0,0)
oTC = oCell.createTextCursor
oVC.gotoRange(oTC,false)
oVC.gotoEnd(true)
If Not oVC.isCollapsed then oVC.gotoEnd(true) 'if cell A1 isn't empty
Copy(oDoc,oVC)
oVC.gotoEnd(false) 'move cursor to paste position
Paste(oDoc,oVC)
End Sub

sub Copy(oDoc,oVC)
dim document   as object
dim dispatcher as object
document   = oDoc.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())
end sub

sub Paste(oDoc,oVC)
dim document   as object
dim dispatcher as object
document   = oDoc.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(document, ".uno:Paste", "", 0, Array())
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 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