Writing perfectly working macro code to import one particular flavour of csv is trivial. This may be what Mr. Coin Bro wants us to do for free. The impertinence is that he tries to tell us what Excel is capable to do.
Next time he will tell us that Excel’s AI assistant can analyze a column of date strings, which is impossible when you import dates with no day number >12. I’m confident that Excel happily imports strings without bothering the user with any prompts.
Just like Calc, Excel prompts for import options every time you open a csv. It does not import anything automatically. Anything I found about Excel guessing import parameters is trivial stuff where everything in the csv matches the office locale.
This discussion about 10, 20, may be 100 mouse clicks per working day has no purpose other than wasting our time.
Sub Open_Specific_Csv()
file = getFileFromFilePickerDialog("~/Downloads/*.csv"))
specific_options = "59,34,ANSI,1,,1031,false,true,true,false,false,0,false,false,true"
Open_CSV file, specific_options
End Sub
Sub Open_CSV(sURL As String, sFilterOptions As String)
Dim aProps(1) as new com.sun.star.beans.PropertyValue
aProps(0).Name = "FilterName"
aProps(0).Value = "Text - txt - csv (StarCalc)"
aProps(1).Name = "FilterOptions"
aProps(1).Value = sFilterOptions
doc = StarDesktop.loadComponentFromURL(file, "_default", 0 aProps())
End Sub
The above code reliably opens the weird sample data from my banking account because of the specific_options passed to the working routine together with a file URL.
Reading the filter options string for a correctly loaded csv is trivial:
Sub showFilterOptions()
Dim args(),i%
args() = StarDesktop.CurrentComponent.getArgs()
for i = 0 to uBound(Args())
if args(i).Name = "FilterOptions" then inputbox args(i).Name,"",cStr(args(i).value)
next
End Sub