I have a CSV file that I want to open and manipulate using a macro.
I set some properties though. However, it seems that the FilterOptions is not working properly, I don’t know why.
When I use the Code Format to each table column, it does not open in the pattern I want.
It will be used in Windows 10.
To understand what I’m saying access the link: Filter Options - Apache OpenOffice Wiki
Macro:
Sub AbrirManipular()
'Defini as variáveis para trabalhar com o documento
Dim oDoc as Object : oDoc = ThisComponent
Dim oSheet as Object : oSheet = oDoc.Sheets
rem-----------------------------------------------------------------------------------------------------
'Defini variáveis que serão utilizadas para abrir o arquivo CSV (DADOSMATRICULA)
Dim UrlMatr as String, CsvMatr as Object, PropsMatr(2) as New com.sun.star.beans.PropertyValue
'PropsMatr(0).Name = “Hidden”
'PropsMatr(0).Value = true
PropsMatr(1).Name = “FilterName”
PropsMatr(1).Value = “Text - txt - csv (StarCalc)”
'OpçõesFiltro = Op_Separadores(Tabela ASCII), Delimitadores de texto, Conj. de 'Caracteres(padrão=0), n. da 1ª linha(padrão=1), FormatoColunas (coluna/CodFormato:padrão=1), 'idioma(padrão="" ou 0), OutrasOp: FormataComoCampoTexto(padrão=false), Detecta n. 'Especial(padrão=false)
PropsMatr(2).Name = “FilterOptions”
PropsMatr(2).Value = “59/9, 34, 9, 1, 1/10, 2/4, 3/9, 4/1, 5/1, 6/9, 7/1, 8/1, 9/1, 0, false, false”
'Caminho do arquivo CSV
UrlMatr = ConvertToUrl (“C:\Users\felipe\Downloads\ParaTeste.CSV”) 'Windows
'Abre o arquivo CSV
CsvMatr = StarDesktop.loadComponentFromUrl (UrlMatr, “default”, 0, PropsMatr() )
End Sub
File with the macro:
MacroFiltroCSV.ods (9,3,KB)
File to open with the macro. Please, after downloading change the file extension for .csv:
ParaTeste.ods (16,6,KB)
I already ask for help in another topic in Portuguese, but nobody showed up to help me.
EDIT
The macro below was very helpful for working on both Linux and Windows OS. Therefore, I will change the solution to facilitate the search of other users. Thank you very much @Villeroy!