[Solved] Macro to open txt document as encoded

The Application Programming Interface and the OASIS Open Document Format

[Solved] Macro to open txt document as encoded

Postby kwalcock » Thu Nov 19, 2015 7:41 am

Community,

How can I load a text (*.txt) document with a macro and also specify that I need what is described in the open dialog as "Text Encoded (*.txt)" so that I can specify the desired paragraph markers? If I have the URL of a txt file, this code opens it for me, but I can't specify the paragraphs.

Reference<XComponent> xComponent(xComponentLoader->loadComponentFromURL(tempFileURL,
OUString(RTL_CONSTASCII_USTRINGPARAM( "_blank" )), 0, properties));

I'm sure that a filter must be spelled out in the properties, but I don't know how to get ahold of one.

Thanks.
Last edited by RoryOF on Thu Nov 19, 2015 10:54 am, edited 1 time in total.
Reason: Added [Solved] and green tick [RoryOF, Moderator]
Apache OpenOffice 4.0.1
Windows, Linux, MacOS
kwalcock
 
Posts: 24
Joined: Thu Oct 09, 2014 11:54 am

Re: Macro to open txt document as encoded

Postby kwalcock » Thu Nov 19, 2015 9:36 am

Step one is to configure the filter with something like

propertyValuesHelper.add("FilterName", Any(OUSTRING("Text (encoded)")));

However, I will also need some FilterOptions or FilterData and it's being difficult to track down what those values should be.
Apache OpenOffice 4.0.1
Windows, Linux, MacOS
kwalcock
 
Posts: 24
Joined: Thu Oct 09, 2014 11:54 am

Re: Macro to open txt document as encoded

Postby Villeroy » Thu Nov 19, 2015 10:06 am

Open the file manually specifying the right encoding, locale, delimiter(s), text delimiter, "special numbers", if text should be enforced for quoted strings and with any exceptions to the rules for selected columns. The locale and "special number" optioins are particularly important because it determines how to interprete strings representing decimals, date/times, booleans etc.

Then call the Basic IDE, paste the following snippet to some module below MyMacros.Standard and run it (F5).
It shows an input box from where you can copy the FilterOptions string which was used to open the current document.
Code: Select all   Expand viewCollapse view
Sub showFilterOptions
Dim args(),i%
   args() = thisComponent.getArgs
   for i = 0 to uBound(Args())
      if args(i).Name = "FilterOptions" then inputbox "","",args(i).value
   next
End Sub
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 26965
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Macro to open txt document as encoded

Postby kwalcock » Thu Nov 19, 2015 10:35 am

Wow! That worked like a charm. Thank you very much.
Apache OpenOffice 4.0.1
Windows, Linux, MacOS
kwalcock
 
Posts: 24
Joined: Thu Oct 09, 2014 11:54 am

Re: [Solved] Macro to open txt document as encoded

Postby kwalcock » Thu Jan 14, 2016 4:12 am

Values I receive look like

"MS_1252,CR,Times New Roman,en-US,"

but unfortunately there is no hint about how a font size can be set. On import of text the font size seems to default to 10pt which is too small for me and not one of any preset defaults that I can find. Does anyone know how font size can be set on import? Alternatively, can some global default be set that will apply to the text. A style "Preformatted Text" is created with font size of 10pt specified, but I can't find where that comes from or how to influence it.
Apache OpenOffice 4.0.1
Windows, Linux, MacOS
kwalcock
 
Posts: 24
Joined: Thu Oct 09, 2014 11:54 am

Re: [Solved] Macro to open txt document as encoded

Postby Villeroy » Fri Jan 15, 2016 1:55 pm

Get StyleFamily "CellStyles", change the properties of style "Default". I would simply increase the zoom factor.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 26965
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany


Return to UNO API and ODF

Who is online

Users browsing this forum: No registered users and 2 guests