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

Inserting a Calc table in a Write document

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


Joined: 28 Feb 2008
Posts: 5

PostPosted: Thu Feb 28, 2008 10:33 am    Post subject: Inserting a Calc table in a Write document Reply with quote

Hi and thanks in advance

This is my case: I have a write document with a macro that opens a calc document. I should take a range of cells from calc and show it on write document as a table. The problem is that while i can select that range acording to some params and i can prepare the write doc to insert the table, i have an object (a range) pointed by a cursor in calc with my desired data, and a suitable place to insert a table pointed by another cursor in write... but this object, logically, is not what is expected by the function "insertTextContent (mycursor,whatishouldinsert,false)" it demands a Table object...

If I create a table and initialize it it works well... but these are not data from calc...

I thought it should be an easy to solve problem, but i get no answer in the web or in the books... i supose i'm missing some simple idea

Please help Smile
Back to top
View user's profile Send private message
Villeroy
Super User
Super User


Joined: 04 Oct 2004
Posts: 10106
Location: Germany

PostPosted: Thu Feb 28, 2008 12:14 pm    Post subject: Reply with quote

You can link sheets, database ranges or derived queries. Just drag a table or query from a registered datasource (hit F4 to show them) into other documents.
Try dragging the simple "Bibliography" example into Writer.
A registered datasource is a Base document which can connect to several sources of tabular data.
Connect your sheet: File>New>Database... [X]Connect existing, type:Spreadsheet, [X]Register
Back to top
View user's profile Send private message
jaume
General User
General User


Joined: 28 Feb 2008
Posts: 5

PostPosted: Fri Feb 29, 2008 2:15 am    Post subject: Reply with quote

Thanks for your answer, Villeroy

i dealed with what you told me, but it's not what i need. My tables are generated automatically by a sheet. This tables might have or not a fixed number of rows. The write document has a macro that reads this generated tables from the sheet and looks for its legnth, avoiding empty cells. It has to be done by a macro... why? because with DDE links (that would be the easiest way in my case) are pointing always to the same sheet. If i copy the pair for a new automatic document, my write file is filled with the data from the original sheet (it's because DDE links use ONLY absolute path... i don't understand why).

I think there must be some way to cast from my range of cells to a table that can be easily inserted... but don't know where to llok for it.

The code is something like this:
Sub main
[...]
oTab = cogeTablaFija(oDoc2,sHoja,sColI,sFilI,sColF,sFilF)
oTexto.insertTextContent(oCursor.getEnd(),oTab,false) 'HERE IT THROWS: "cannot coerce argument type during corereflection call"
End Sub

Function cogeTablaFija (oD as Object, sH as String, sCI as String, sFI as String, sCF as String, sFF as String) as Object
Dim oRango as Object
Dim oCursorCeldas as Object
Dim iFI as Integer, iFF as Integer, iCI as Integer, iCF as Integer
iFI = VAL(sFI) - 1
iFF = VAL(sFF) - 1
iCI = StringANumero(sCI)
iCF = StringANumero(sCF)
oH = oD.getSheets().getByName(sH)
oCursorCeldas = oH.createCursorByRange(oH.getCellRangeByPosition(iCI,iFI,iCF,iFF))
oRango = oCursorCeldas.getRangeAddress()
cogeTablaFija = oRango
End Function
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