Admitted, a cheesy title line if I ever saw one…
It’s been a bit quiet in here lately, could be because I exchanged my keyboard and desk for this during most of October:
That’s Indonesia, at the beginning of the rainy season.
But now to matters at hand:
Exporting Listbox content!
I am pretty sure many of you already have something in place for this, but even for those, my new component
could be interesting.
It (currently) is a true one trick pony, and all it does is export a listbox either into a file or into the clipboard. It automatically handles all that’s needed and works with array and selection based listboxes, the latter even taking care of calculated columns.
You can use it without any configuration, by just dropping it into your listbox method maybe like this:
if((form event=on clicked) & contextual click)
It automatically recognizes the current listbox and takes care of everything, asks for a format, destination and does its magic, all without any configuration needed.
If you install the XLS II plugin by Keisuke, you can even select to write the listbox content directly into an Excel file (.xls).
Of course, you can also finely control what the method does, passing which Listbox to export and a whole lot of parameters to determine how that happens.
$p_ListBox:=object get pointer(object named;"MyListbox")
OB Set($o_Param;"TargetPath";"C://users/me/desktop/my exported listbox.csv")
In the first parameter pass a pointer to the listbox, pass a nil pointer if you want it to find the listbox itself but want to pass some options in the second parameter.
Seid second parameter is an object that can contain a truckload of options. Ok, maybe only a pickup truck of options, a compact, oh hell ok, a pushcart.
Here are the options for the parameter object:
- ColNames (array text)|ColNumbers (array long)
Array with the desired column object names or the column numbers.
If one of these is passed, the export will be in the order of the columns passed and there will be no checking of column invisibility or formula result type (for listbox selection only)
- NoHeader (boolean)
Do not write a header line with the column names. defaults to FALSE
- MaxLines (longint)
The maximum number of lines to export, if empty or 0, all lines will be written
- ShowInvisibleCols (boolean)
Show invisible columns. Ignored if ColNames or ColNumbers was passed. defaults to FALSE
- ShowInvisibleRows (boolean)
Show invisible rows. Only for array-based listboxes. defaults to FALSE
- TargetCode (text)
The export target. If not passed, users will be able to select.
possible values are:
- file_csv – a standards compliant csv file with a comma “,” as a separator, text in double quotes and decimal separators switched to period “.”
- clip_csv – the same csv but to clipboard
- file_txt – a text file according to specifications passed or their defaults
- clip_txt – the same text but to clipboard
- file_xls – only useful if Keisukes plugin XLS II.bundle is available.
Will write an XLS file
- TargetPath (text)
The path to the file to be created. If not passed, the user will be shown a file creation dialog
- CharSet (text)
The character set for the export will default to platform defaults:
- win : ISO-8859-1
- mac : UTF-8
- ProgressRowCount (longint)
Only show progress if the number of rows exceeds, defaults to 0
- NoProgress (boolean)
Do not show a progress bar when collecting the data, defaults to FALSE
The next 3 parameters are only used for export target TXT
- FieldSep (text)
The desired field separator defaults to tab (char 9)
- RecSep (text)
The desired record separator defaults to platform defaults
- NotDblQuoteText (boolean)
When exporting text fields, do not double quote the cell value, defaults to FALSE
Now a few parameters to control Excel XLS export, available if the XLS II Plugin by Keisuke is present.
- XLS_NumFormat (text)
excel format string for numbers i.e. “#,##0.00” – Excel takes care of the different decimal and thousand separators
- XLS_DateFormat (text)
excel format string for date i.e. “YYYY-MM-DD;@” – defaults to “DD.MM.YYYY;@”
- XLS_TimeFormat (text)
excel format string for time i.e. “hh:mm;@” – defaults to “hh.mm.ss;@”
- XLS_BoolTrue (text)
Text representation of boolean value for TRUE i.e. “X”, defaults to numeric 1
- XLS_BoolFalse (text)
Text representation of boolean value for FALSE i.e. “-“, defaults to numeric 0
As for the formats, you can read up on the options in a Microsoft support article here
Ok, now enjoy and download here:
The source is in the package and password protected. Just contact me an I will send you the password. The reason for this is that I would like to get a feeling for the interest within the 4D community for my contributions.
Also as always, a donation would be highly welcome in case you use it.
The donate button is on your right.
Your LBTools looks great. I have written code to do the same but not to the level of detail that you have. Please send me the password.
During the current times of crisis, I will make most of my components available in source, just give me few days.
Currently there is one issue when using LB_tools: it does not work with Listboxes based on entity selections (ORDA) or Collections that are passed as property of an object (i.e.: Form.mySelection).
4D will need to provide us with tools to get the correct data source, once this is done, it should work.
Maybe, as a work-around I will add parameters to be passed in order to set the data source of the listbox, not really generic, but hey, if it works…