I filed a feature request over at https://bugs.documentfoundation.org/show_bug.cgi?id=99035. What I’m trying to do is convert Selected text to a table, whose number of columns will vary, depending on the data. The problem is that in the scanned documents I work on, each data entry is on its own line:
word1
word2
word3
word4
word5
word6
Someone mentioned the trick of adding tabs to the first line, and indeed, this creates a table with a corresponding number of columns, which is pretty neat. But the data is not filled into those extra columns, they remain empty. The data continues to be populated, each line into a new row. IOW, if the original text, with added tabs, is:
word1 tab tab
word2
word3
word4
word5
word6
It converts to:
word1 col2 col3
word2
word3
word4
word5
word6
Whereas I would like it to be:
word1 word2 word3
word4 word5 word6
I suppose the best way to get at this is a macro 1) converting linefeeds to delimiters, 2) within a selection, 3) leaving every Nth feed untouched(specified at the running of the macro), 4) applied before table conversion.
Has anyone dealt with this or have an idea? Thanks.
Edit:
Please see @librebel’s excellent solution below. It does exactly what I was asking for. I only added an Input box to spec number of columns on the fly, and a premature exit if that number is 0:
If oDocument.supportsService( "com.sun.star.text.TextDocument" ) Then
Dim iNumColumns As Integer
iNumColumns = InputBox("Enter desired number of columns (blank = 0)")
If iNumColumns <= 0 Then GoTo Exit1
...
Exit1:
End Sub