Hi,
After reading through the replies and some more in depth search on the net, it appears that importing from Excel with proper formatting (numbers as text) will solve the leading zeros truncate problem as PHPExcel is able to retrieve cell format information from XLS file. The problem exists with CSV files and PHPExcel. That is because CSV files as basically pure text files with no formatting, thus PHPExcel will assume all fields with pure numbers as integers will during import, drops the leading zeros before inserting into the DB.
EDIT: Looking through some code on the import module, maybe we can use a better function than $this->getValue(). This is because this function doesnt import dates correctly, resulting in a default php date of 1 Jan 1970. Using $this->getFormattedValue() corrects the behaviour.
private function import($file) {
// require_once 'PHPExcel/IOFactory.php';
try {
$xls = Libs_PHPExcelCommon::load($file);
// $xls = PHPExcel_IOFactory::load($file);
} catch(Exception $e) {
print(__('Unable to parse uploaded file, invalid XLS or CSV').'<br>'.$e->getMessage());
return false;
}
$uploaded_data = array();
foreach($xls->getAllSheets() as $sheet) {
$cols = null;
foreach($sheet->getRowIterator() as $row) {
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false);
if($cols===null) {
$cols = array();
foreach ($cellIterator as $j=>$cell) {
$cols[$j] = $cell->getFormattedValue();
}
} else {
$tmp = array();
foreach ($cellIterator as $j=>$cell) {
if(!isset($this->col_flip_names[$cols[$j]]))
continue;
$tmp[$this->col_flip_names[$cols[$j]]] = trim($cell->getFormattedValue());
}
$uploaded_data[] = $tmp;
}
}
}
if(!$uploaded_data) {
print('Specified file contains no data');
return false;
}
$this->data = $uploaded_data;
return true;
}