There is a issue in Excel where it adds the phone numbers as a function +!-604-555-5555 thinking that it is
1
-604
-555
-5555
This code will solve this issue and also converts it to a .Tab file:
<?php^M
/**^M
* Download file^M
*^M
* @author Paul Bukowski <pbukowski@telaxus.com>^M
* @copyright Copyright © 2006, Telaxus LLC^M
* @version 1.0^M
* @license MIT^M
* @package epesi-utils^M
* @subpackage RecordBrowser^M
*/^M
if(!isset($_REQUEST['cid']) || !isset($_REQUEST['path']) || !isset($_REQUEST['tab']) || !isset($_REQUEST['admin'])) die('Invalid usage - missing param');^M$cid = $_REQUEST['cid'];^M
$tab = $_REQUEST['tab'];^M$admin = $_REQUEST['admin'];^M
$path = $_REQUEST['path'];^M
^M
define('CID', $cid);^M
define('READ_ONLY_SESSION',true);
require_once('../../../include.php');^M
$crits = Module::static_get_module_variable($path, 'crits_stuff', null);^M
$order = Module::static_get_module_variable($path, 'order_stuff', null);^M
if ($crits===null || $order===null) {^M
$crits = $order = array();^M
}^M
ModuleManager::load_modules();^M
if (!Utils_RecordBrowserCommon::get_access($tab, 'export') && !Base_AclCommon::i_am_admin())^M
die('Access denied');^M
^M
set_time_limit(0);
$tab_info = Utils_RecordBrowserCommon::init($tab);^M
$records = Utils_RecordBrowserCommon::get_records($tab, $crits, array(), $order, array(), $admin);^M
^M
header('Content-Type: text/csv');^M
//header('Content-Length: '.strlen($buffer));^M
header('Content-disposition: attachement; filename="'.$tab.'_export_'.date('Y_m_d__h_i_s').'.tab"');^M
if (headers_sent())^M
die('Some data has already been output to browser, can\'t send the file');^M
$cols = array('Record ID');^M
foreach ($tab_info as $v) {^M
$cols[] = _V($v['name']);^M
if ($v['style']=='currency') $cols[] = _V($v['name']).' - '.__('Currency');^M
}^M
$f = fopen('php://output','w');^M
//fwrite($f, "\xEF\xBB\xBF");^M
fputcsv($f, $cols, "\t");^M
$currency_codes = DB::GetAssoc('SELECT symbol, code FROM utils_currency');^M
^M
function rb_csv_export_format_currency_value($v, $symbol) {^M
static $currency_decimal_signs=null;^M
static $currency_thou_signs;^M
if ($currency_decimal_signs===null) {^M
$currency_decimal_signs = DB::GetAssoc('SELECT symbol, decimal_sign FROM utils_currency');^M
$currency_thou_signs = DB::GetAssoc('SELECT symbol, thousand_sign FROM utils_currency');^M
}^M
$v = str_replace($currency_thou_signs[$symbol], '', $v);^M
$v = str_replace($currency_decimal_signs[$symbol], '.', $v);^M
return $v;^M
}^M
^M
foreach ($records as $r) {^M
$rec = array($r['id']);^M
foreach ($tab_info as $v) {^M
ob_start();^M
$val = Utils_RecordBrowserCommon::get_val($tab, str_replace('%%','%',$v['name']), $r, true, $v);^M
ob_end_clean();^M
$val = str_replace(' ',' ',htmlspecialchars_decode(strip_tags(preg_replace('/\<[Bb][Rr]\/?\>/',"\n",$val))));^M
if ($v['style']=='currency') {^M
$val = str_replace(' ','_',$val);^M
$val = explode(';', $val);^M
if (isset($val[1])) {^M
$final = array();^M
foreach ($val as $v) {^M
$v = explode('_',$v);^M
if (isset($v[1])) ^M
$final[] = rb_csv_export_format_currency_value($v[0], $v[1]).' '.$currency_codes[$v[1]];^M
} ^M
$rec[] = implode('; ',$final);^M
$rec[] = '---';^M
continue;^M
}^M
$val = explode('_', $val[0]);^M
if (!isset($val[1])) {^M
$rec[] = '0';^M
$rec[] = '---';^M
continue;^M
}^M
if(isset($currency_codes[$val[0]])) {
$tmp = $val[1];
$val[1] = $val[0];
$val[0] = $tmp;
} elseif(!isset($currency_codes[$val[0]])) { //there is no currency code? skip parsing
$rec[] = $val[0];^M
$rec[] = $val[1];^M
continue;
}
$rec[] = rb_csv_export_format_currency_value($val[0],$val[1]);^M
$rec[] = isset($currency_codes[$val[1]])?$currency_codes[$val[1]]:$val[1];^M
} else {^M
$rec[] = $val;^M
}^M
}^M
foreach($rec as & $entry)
{
$entry = "=LEFT(\"$entry\", 99)";
}
fputcsv($f, $rec, "\t");^M
}^M
?>^M
I hope you find it useful
I used this to replace modules/Utils/RecordBrowser/csv_export.php