Page 1 of 1

[Solved] Macro to open txt document as encoded

PostPosted: Thu Nov 19, 2015 7:41 am
by kwalcock
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.

Re: Macro to open txt document as encoded

PostPosted: Thu Nov 19, 2015 9:36 am
by kwalcock
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.

Re: Macro to open txt document as encoded

PostPosted: Thu Nov 19, 2015 10:06 am
by Villeroy
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

Re: Macro to open txt document as encoded

PostPosted: Thu Nov 19, 2015 10:35 am
by kwalcock
Wow! That worked like a charm. Thank you very much.

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

PostPosted: Thu Jan 14, 2016 4:12 am
by kwalcock
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.

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

PostPosted: Fri Jan 15, 2016 1:55 pm
by Villeroy
Get StyleFamily "CellStyles", change the properties of style "Default". I would simply increase the zoom factor.