我正在尝试上传包含财务数据的Excel工作表。它在A列上有帐号,当我上传工作表时,COL A数据附带“ x000D ”。当我谷歌这时它说明与细胞上隐藏的换行有关。有人知道如何从细胞中删除这些换行符吗?感谢
function import_data($filename, &$new_chart_accounts, $extension = '') {
$this->init_worksheet($filename, $extension);
$entries = array();
$new_chart_accounts = array();
$chart_accounts = ChartAccounts::read_all(true);
$cha_description;
$indent = $this->dimension[0][0];
for ($row = $this->dimension[0][1] + 1; $row < $this->dimension[1][1]; $row++) {
$entry = array();
for ($col = $this->dimension[0][0]; $col <= $this->dimension[1][0]; $col++) {
if ($this->sheet->cellExistsByColumnAndRow($col, $row)) {
$cell = $this->sheet->getCellByColumnAndRow($col, $row);
$style = $this->sheet->getStyle($cell->getCoordinate());
$fill = $style->getFill();
if ($fill->getFillType() == PHPExcel_Style_Fill::FILL_NONE
|| ($fill->getFillType() == PHPExcel_Style_Fill::FILL_SOLID && $fill->getStartColor()->getRGB() == 'FFFFFF')) {
$value = trim($cell->getValue());
//print $value;
switch ($col) {
case self::ACCOUNT_NUMBER:
$entry['cha_number'] = $value;
break;
case self::ACCOUNT_DESCRIPTION:
$entry['cha_description'] = $value;
break;
case self::AMOUNT:
case self::AMOUNT_2:
$value = str_replace(array(',', '$'), '', $value);
// $sign = substr($value, strlen($value) - 2, 2);
// if ($sign == 'cr' || $sign == 'dr') {
// $value = str_replace($sign, '', $value);
// } else {
// $sign = 'dr';
// }
// $entry['sign'] = $sign;
// if ($value != '' && is_numeric($value)) {
// $entry['data_amount'] = $value;
// }
$entry['data_amount'] = $value;
}
}
}
}
答案 0 :(得分:2)
这将替换字符串中包含的任何空格,并将获取格式为
的单元格值$cellValue = str_replace(' ', '', $cell->getFormattedValue());
希望这会有所帮助,如果我们可以拥有您的Excel文件的副本会更好。感谢。