Macro Calc: Convert column to date - similar "Text to Columns..."

With Calc, you don’t need any pre-processing. It can import all kinds of reasonably valid csv.
How to import csv into Calc by macro:

  1. Open your specific flavor of csv manually with locale, char set and all options properly set.
  2. Run this code against the active csv document:
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
  1. Copy the FilterOptions into your code which may be as simple as this:
dim p(1) as new com.sun.star.beans.PropertyValue
p(0).Name = "FilterName"
p(0).Value = "Text - txt - csv (StarCalc)"
p(1).Name = "FilterOptions"
p(1).Value = "your_specific_filter_options_string"
doc = StarDesktop.loadComponentFromURL(convertToURL(sysPath), "_blank", 0, p())
2 Likes

Thanks again @Villeroy. This works perfectly!

  1. Select the column of wrongly imported date strings
  2. Call the number format dialog and change the number format language for the selected cells to “English (UK)” or any other non-US English.
  3. menu:Edit>Find&Replace…
    3.1 Check “Current Selection Only”
    3.2. Check “Regular Expression”
    3.3. Search for: .+
    3.4. Replace with: &
    3.5. Button [Replace All…]

Now you have converted the strings into numbers. Apply any number format in any number format locale you want.

1 Like