0

I am having trouble when copying a row from one sheet to another in the same Excel file. Some cells contain large numbers, which creates a problem when copying them because they get rounded up and I don't want that to happen. I heard I can overcome that problem by pasting them as a string, as shown here. But no matter what I do the values of the cells are still formatted as numbers, which messes up the whole process.

Can you please help me? Thanks!

Excerpt code:

//por ultimo lo demas
    for($i=2; $i<$rowCount;$i++){
        $order = $objPHPExcel->getActiveSheet()->getCell('B'.$i)->getValue();
        if($order != 'xxx'){
            $cellValues = $objPHPExcel->getActiveSheet()->rangeToArray("A$i:AP$i", null, true, true, false);
            $objPHPExcel->setActiveSheetIndex(1);
            PHPExcel_Cell::setValueBinder(new PHPExcel_Cell_MyColumnValueBinder($cellValues));
            $objPHPExcel->getActiveSheet()->fromArray($cellValues, null, 'A'.$newRow);
            $newRow++;
            $objPHPExcel->setActiveSheetIndex(0);
            $objPHPExcel->getActiveSheet()->setCellValue('B'.$i, 'xxx');
        }
    }
Julio Garcia
  • 393
  • 2
  • 7
  • 22
  • 1
    Why do you think that passing the cell values to `PHPExcel_Cell_MyColumnValueBinder()` is correct? The page you've linked passes an array of column addresses that should be treated as string data (`PHPExcel_Cell::setValueBinder(new PHPExcel_Cell_MyColumnValueBinder(['A', 'B', 'C', 'E', 'F']));`), not values from cells – Mark Baker Nov 14 '17 at 17:29
  • It was all I found. I wanted to try it out since nothing seemed to work – Julio Garcia Nov 14 '17 at 17:32
  • 1
    And unless you have different rules for every row, you don't need to set the binder for every row; just set it once before the loop – Mark Baker Nov 14 '17 at 17:32
  • @MarkBaker the only rule I want is for it to be displayed as String. That's all – Julio Garcia Nov 14 '17 at 17:33
  • 1
    For what to be displayed as string? Which columns? If it's every column, then modify that binder code so it treats every value as string without needing to check columns at all – Mark Baker Nov 14 '17 at 17:34
  • Every single cell (for ease). – Julio Garcia Nov 14 '17 at 17:37
  • Then write a binder that just does `$cell->setValueExplicit((string) $value, PHPExcel_Cell_DataType::TYPE_STRING); return true;` – Mark Baker Nov 14 '17 at 17:53

0 Answers0