

CHANGE TEXT ENCODING OF .TXT FILE CODE
Then i ran this code i found on the internet on the imported file: Sub showFilterOptions I determined the FilterOptions i need for my text file by manually opening it and choosing the needed import settings trough the GUI. tInputStream(oUcb.OpenFileRead(sPath))įind the strings for the encoding in column 2 in Character Sets OInputStream = createUnoService(".TextInputStream") OUcb = createUnoService(".SimpleFileAccess") OFileDialog = CreateUnoService(".dialogs.FilePicker")Īnd then for to read the lines sub LineRead_Win1252ĭim oUcb as variant 'for If your source is not a csv file, but you only want to read a file line by line, then you can use these macros.įor to get the path to the file: Function GetPath as string You need to know the encoding exactly to get the correct number from the table “Character set”. For the meaning of the parameters see Filter Options - Apache OpenOffice Wiki.

There is a macro in Calc: open and save csv-file with given filter options only a line dim oDlg as variant is missing there. The error Message is: “BASIC runtime error. Unfortunately this codes fails at “Open Mydoc For Input As File_Number”. MyDoc = StarDesktop.LoadComponentFromURL(ConvertToURL("file_name.txt"), "_blank", 0, props() ) Props(0).Value = "Text - txt - csv (StarCalc)" I realise that i have to use code that looks somewhat like this: Dim MyDoc As Objectĭim props(1) As New .PropertyValue How can i make Libre Office interpret my text file as ANSI encoded? ä, ß …) to be incorrectly displayed as some strange (?) symbol. This causes certain special characters (e.g.

However Libre Office seems to interpret it as UTF-8 encoded. In order to be imported correctly, my text file has to be interpreted as ANSI encoded. I have written a macro that reads line after line of a text file into a string variable: open file_name for input as file_number
