Convert text to table code example

Creating a macro - Writing a Script - Using the API

Convert text to table code example

Postby Echoplex » Mon Mar 31, 2014 7:55 pm

Hello everyone.

I'm writing a c# program which uses OO and now I have some trouble using OO API. I need to convert the formatted text(tabs) into the table. After a lot of searching I found convertToTable function which receive few parameters that I didn't understand. Somebody, please post the code on C# (or Java) how to use this function, and if you may write down list of all properties (Cell, Row, Table).

Thanks.
OpenOffice 4.0.1 on Windows 7
Echoplex
 
Posts: 7
Joined: Mon Mar 31, 2014 7:10 pm

Re: Convert text to table code example

Postby Villeroy » Mon Mar 31, 2014 8:25 pm

You can query all properties, methods and services from any UNO object. Install the MRI function and read the MRI tutorial on this forum.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Villeroy
Volunteer
 
Posts: 29722
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Convert text to table code example

Postby Echoplex » Wed Apr 02, 2014 11:43 am

Yes, that is not a problem. But I can't figure out how to use these parameters properly when I call convertToTable method. Here's how I try to call it:
Code: Select all   Expand viewCollapse view
XTextRange str;
str.setString(data); //data is string with formatted text
XTextConvert XTC;
XPropertySet CellProperties = (XProperty)XTC;
XPropertySet RowProperties = (XProperty)XTC;
XPropertySet TableProperties = (XProperty)XTC;
table = XTC.convertToTable(str, CellProperties, RowProperties, TableProperties); //table is XTextTable object

Error: Invalid arguments.

I tried a lot of ways but none of them is working. So I came here for help.
OpenOffice 4.0.1 on Windows 7
Echoplex
 
Posts: 7
Joined: Mon Mar 31, 2014 7:10 pm

Re: Convert text to table code example

Postby B Marcelly » Wed Apr 02, 2014 12:20 pm

Hi,
Echoplex wrote:I need to convert the formatted text(tabs) into the table.

I am not sure what is your problem.
Is your original text a csv file ? (simple text file with fields separated by tabs)
Do you really want to obtain a table in a Writer document ?

If the answer is yes to both questions, I suggest you forget about convertToTable() and instead read your input file by program and fill the Writer table cell by cell.
Other solution : the dispatcher (Macro recorder) seems to work well.
Bernard

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
B Marcelly
Volunteer
 
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: Convert text to table code example

Postby Villeroy » Wed Apr 02, 2014 12:26 pm

If it is about csv, connect a Base document and create a report (which is a Writer table).

Hint: Download and extract the attached zip from my spreadsheet topic [Example] Loading CSV into preformatted spreadsheets
Open the CSV_Database.odb
Click the Tables container, right-click Table1 (which is a representation of file Table1.csv) and choose "Report Wizzard".
Add all columns and finish. The resulting report is a Writer document with all data from Table1.csv dynamically linked.
Last edited by Villeroy on Wed Apr 02, 2014 1:15 pm, edited 1 time in total.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Villeroy
Volunteer
 
Posts: 29722
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Convert text to table code example

Postby Echoplex » Wed Apr 02, 2014 1:13 pm

Hi everyone!

No, I have string with text, like:
Code: Select all   Expand viewCollapse view
111\t222\t333\n444\t555\t666

and this string convert to table.
For Example: https://wiki.openoffice.org/wiki/Docume ... a_table%3F
OpenOffice 4.0.1 on Windows 7
Echoplex
 
Posts: 7
Joined: Mon Mar 31, 2014 7:10 pm

Re: Convert text to table code example

Postby B Marcelly » Wed Apr 02, 2014 2:07 pm

As usual, without a real example from real data, it's a guess work.
From what you show, my previous answer is still valid.
Bernard

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
B Marcelly
Volunteer
 
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: Convert text to table code example

Postby Echoplex » Wed Apr 02, 2014 2:46 pm

I have one program which generates a mass of text for filling .dot file. Parts of this text need to be converted into tables. That program can fill such file using MS Office API but I also need to make the same things with Open Office API. Filling tables cell by cell takes a lot of time. I need to use convertToTable method because it converts text separated by tabs into table. But problem is that I can't find any examples of use this method in documentation of OO API.
OpenOffice 4.0.1 on Windows 7
Echoplex
 
Posts: 7
Joined: Mon Mar 31, 2014 7:10 pm

Re: Convert text to table code example

Postby Villeroy » Wed Apr 02, 2014 5:34 pm

Read the entire text string into a variable.
Analyse the column count (tabs.count +1) and the row count
Create a table with rows and columns as needed.
Split your text lines by tabs and fill the resulting arrays into the table.
What's so difficult about it? You are in a hurry and need the solution now. On the other hand did not even spend 10 hours with macro programming in OpenOffice. 10 hours time of learning about UNO is close to nothing but after 10 hours playing with other peoples code, object inspectors and documentation you would have enough knowledge to ask the right questions properly.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Villeroy
Volunteer
 
Posts: 29722
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Convert text to table code example

Postby Echoplex » Wed Apr 02, 2014 8:37 pm

Thank you that you're trying to help me but I found the method which I need (yes, convertToTable) and this method should do what I need without any hacks. The problem is that I have no clue how to properly call it, mostly how to make parameters received by this method. I read all the OO API manuals which I found, I read wiki, I read other people's code but I didn't find anything what can help me to solve the issue. That's why I wrote my question on this forum.
OpenOffice 4.0.1 on Windows 7
Echoplex
 
Posts: 7
Joined: Mon Mar 31, 2014 7:10 pm

Re: Convert text to table code example

Postby Villeroy » Wed Apr 02, 2014 9:11 pm

All this macro programming with OpenOffice is the opposite of productivity and you may spend another day investigating the source code about valid names and types of property values for this particular method. Possibly you are the first person on the planet who wants to split tab-delimited text this way. If you have a program that does the trick with MS Word, why don't you want to use it? Reportedly, recent versions of MS Word support ODF. Let your VBA macro convert to table and save a .odt copy.
Next thing you can try is the macro recorder but I doubt that it comes up with any working code snippet.
Then you may write a macro to store a Word doc as plain text, run a database report on this file, save the report as .odt, close the report, replace the text file with the next shit, re-run the report, save the report, close the report and so on.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Villeroy
Volunteer
 
Posts: 29722
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Convert text to table code example

Postby JeJe » Sat Feb 20, 2021 3:36 am

(Albeit 7 years later)...I resurrected this topic in a new thread with MrProgrammer providing the solution, here:

viewtopic.php?f=20&t=104535&p=506723#p506723
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1537
Joined: Wed Mar 09, 2016 2:40 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 9 guests