csv export

coullet

Member
Hi,


i want to make a cvs export for a soft that need specific params for separator and character set, but there is no option for that in the list cvs export.
How it's possible to do that?

Thanks!
 
You can override the sepchar for CSV export in Fabrik's global settings, under the Lists tab, although that will obviously affect all exports, not per-list.

There is an encoding option on the CSV params (list, publishing, CSV), although it's currently restricted to just four options ...

Code:
                    <option value="UTF-8">UTF-8</option>
                    <option value="UTF-16">UTF-16</option>
                    <option value="UTF-16LE">UTF-16LE</option>
                    <option value="ISO-8859-15">ISO-8859-15</option>

If you need a different option, you could try adding it to that menu - edit /administrator/com_fabrik/models/forms/list.xml, around line 760. If your encoding works, let me know and I'll add it to the options in github.

-- hugh
 
All we really do with the encoding is set the 'charset' header with it. And if in Excel mode, we'll do a mb_convert_encoding() from UTF-8 to your selected charset, which we think fixes some issues with accented characters.

-- hugh
 
ok
I've find that mb_convert_encoding don't support MacRoman
iconv does but need to be installed on the server...
 
Yup. That's why we use mb_convert_encoding. :)

There are some examples in our code where we use iconv, but test for it first, like ...

Code:
if (function_exists('iconv')) {
   $foo = iconv(blah blah);
}
else {
   $foo = mb_convert_encoding(blah blah);
}

So you could try that approach in the csvimport.php model. You'll probably find iconv is installed, as most installs of PHP these days are built with it. In fact there's a several places in the J! code where it's used without being tested for.

-- hugh
 
Thanks.
I don't find csvimport.php.
Is it in this file i need to make change, or i misunderstand what you say?
 
components\com_fabrik\models\csvexport.php
around line 500

Keep in mind that this is a Fabrik core file and any modifications will be overridden by the next update.
 
Ooops, yes, export, not import. :)

If you get it working to support macroman (without breaking anything else) I'll apply the changes in github. I can't do it, as I don't have a Mac.

-- hugh
 
ok...i was looking in administrator dir...

I've make something that work with
return iconv('UTF-8', $csvEncoding, $n);
and
<option value="macintosh">Mac Roman</option>

but before purpose change on github:
i don't know the best place to put this line.
in your code i don't understand why you make conversion only if output format is excel
so with output "normal" csv there is no conversion even if we don't chose utf-8?
 
And another tweak...i need no double quote!
I can change the quote function, but if it's possible to have that as an option
 
I know very little about this code, I've never really worked on it before.

I don't see any reason why we shouldn't to encoding on non Excel format, so you could try modifying the code so it doesn't do that test for Excel format, and just converts if the selected format isn't UTF-8.

-- hugh
 
Ok i'll do that.

I'm trying to add an option to put or not double quoti in export:
- i add option in xml file

- i add in csvexport.php:
a new property : public $doubleQuote = true;
and trying to retrieve with
$this->doubleQuote = (boolean)$input->get('csv_double_quote', true);

Is there another things to do to retrieve setting value?
 
The usual way would be to add it as a setting on the backend, so in the csv section of the list form XML, ./administrator/components/com_fabrik/models/forms/list.xml, and adding the language tags to the en-GB backend language file, then use ...

(if it isn't already in the function you are using ...)

Code:
$params = $this->model->getParams();

... then ...

Code:
$doubleQuote = $params->get('csv_double_quote', '1') === '1';

BTW, are you using git? If you want these changes to be merged into the core, the best way is going to be submitting a PR. Which requires forking the code on github, and modifying your fork.

-- hugh
 
i added these changes on github:

-double quote option
-filename with today's date insert (if blank, use list name)
-local delimiter override global parameter
-Mac roman encoding
-encoding not only for excel format
 
OK, I'll merge when I get a few mins to test. Not sure about the double encoding, doing an iconv then unconditional mb_convert_encoding, but I'll fix that if it's an issue.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top