Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

If the file is in *.csv format then you NOT NEED delete columns AFTER load, you can do it BEFORE. Please look this page - Filter Options

With this info your macro will be very small, something like as

Dim sUrl As String
sUrl = convertToURL("C:\FakePath\some_data.csv")
Dim OpenProp(1) as New com.sun.star.beans.PropertyValue
OpenProp(0).name="FilterName"
OpenProp(1).name="FilterOptions"
OpenProp(0).value="Text - txt - csv (StarCalc)"
OpenProp(1).value="44,34,25,1,1/9/2/9/3/9/4/9/7/9/15/9/18/9/36/9/38/9/39/9/40/9/43/9/48/9/49/9/50/9/51/9/52/9/55/9/56/9/57/9/58/9/59/9/60/9/61/9/62/9/67/9/82/9/83/9/93/9/94/9/95/9/96/9/97/9/99/9/100/9/101/9/102/9/103/9,1031,false,true"
If Not FileExists(sUrl) Then Exit Sub
oDoc = stardesktop.LoadComponentFromURL(sUrl, "_blank",0, OpenProp())

In other words, you just need to list the values of "column number / 9 (hidden)" and use this string as the CSV file import filter parameter.

NB Thoroughly check this code on various data - there is a possibility that not all rows will be read into the table (see bug 90653)