Skip to content

Commit

Permalink
Merge pull request #48 from wjcheers/master
Browse files Browse the repository at this point in the history
[FEATURE] Make CSV exports in UTF-8 readable for Excel #41
  • Loading branch information
RussH committed Sep 24, 2015
2 parents 3cb3804 + 0616b6c commit 680806d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@
/* AJAX Encoding. */
define('AJAX_ENCODING', 'UTF-8');

/* Insert BOM in the beginning of CSV file */
/* This is UTF-8 BOM, EF BB BF for UTF-8 */
define('INSERT_BOM_CSV_LENGTH', '3');
define('INSERT_BOM_CSV_1', '239');
define('INSERT_BOM_CSV_2', '187');
define('INSERT_BOM_CSV_3', '191');
define('INSERT_BOM_CSV_4', '');

/* Path to modules. */
define('MODULES_PATH', './modules/');

Expand Down
17 changes: 17 additions & 0 deletions lib/DataGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -1470,6 +1470,23 @@ public function drawCSV()
header('Connection: close');
header('Content-Type: text/x-csv; name=export.csv');

if (defined('INSERT_BOM_CSV_LENGTH') && (INSERT_BOM_CSV_LENGTH > 0))
{
echo chr(INSERT_BOM_CSV_1);
if (INSERT_BOM_CSV_LENGTH > 1)
{
echo chr(INSERT_BOM_CSV_2);
}
if (INSERT_BOM_CSV_LENGTH > 2)
{
echo chr(INSERT_BOM_CSV_3);
}
if (INSERT_BOM_CSV_LENGTH > 3)
{
echo chr(INSERT_BOM_CSV_4);
}
}

echo $headerRow;

foreach ($this->_rs as $rowIndex => $row)
Expand Down

0 comments on commit 680806d

Please sign in to comment.