Determine csv import filter options

Creating Extension - Shared Libraries
Forum rules
For sharing working examples of macros / scripts. These can be in any script language supported by OpenOffice.org [Basic, Python, Netbean] or as source code files in Java or C# even - but requires the actual source code listing. This forum is not for asking questions about writing your own macros.

Determine csv import filter options

Postby ms777 » Sat Oct 17, 2020 6:51 pm

... this is a repost from the old oooforum.org. It helps you if you want to automatize the csv import with non trivial import options

Good luck,

ms777
Code: Select all   Expand viewCollapse view
Sub Main
sUrl = ConvertToUrl("C:\Users\Martin\Downloads\test.csv")
sResult = GetFilterOptionsFromCSVImportDialog(sUrl)
msgbox sResult
End Sub

function GetFilterOptionsFromCSVImportDialog(sUrl) as String
GetFilterOptionsFromCSVImportDialog = ""

oSFA = createUNOService ("com.sun.star.ucb.SimpleFileAccess")
oInputStream = oSFA.openFileRead(sUrl)

Dim aProps(3) as new com.sun.star.beans.PropertyValue
aProps(0).Name = "FilterOptions"
aProps(0).Value = ""
aProps(1).Name = "URL"
aProps(1).Value = sUrl
aProps(2).Name = "FilterName"
aProps(2).Value = "Text - txt - csv (StarCalc)"
aProps(3).Name = "InputStream"
aProps(3).Value = oInputStream

'o = createUnoService("com.sun.star.ui.dialogs.FilterOptionsDialog")
o = createUnoService("com.sun.star.comp.Calc.FilterOptionsDialog")
o.setPropertyValues(aProps())

if o.execute() = com.sun.star.ui.dialogs.ExecutableDialogResults.OK then
  aPropOut = o.getPropertyValues()
  GetFilterOptionsFromCSVImportDialog = aPropOut(0).Value
  endif
oInputStream.closeInput()
end function
ms777
Volunteer
 
Posts: 137
Joined: Mon Oct 08, 2007 1:33 am

Return to Code Snippets

Who is online

Users browsing this forum: No registered users and 1 guest