How could assign an specific data type to a column or cell.

Topics: User Forum
May 30, 2011 at 11:00 AM

Hello, i want  assign a Numeric Data Type into a column or a cell but i don´t know how can do it.

For instance i want to assign a numeric data type into 'R' column .I set 'R' column cell values as follows:

$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(17,$cont, $row[3]);

How could i assign to this cell or to entire 'R' Column the numeric data type?

May 30, 2011 at 3:33 PM

You need to get its NumberFormat from its style like so:

$numberformat = $objPHPExcel->getStyleByColumnAndRow(17, $cont);

The $format can be any format constants found in the PHPExcel_Style_NumberFormat class. They all start with "FORMAT_".

For your needs:

$numberformat = $objPHPExcel->getStyleByColumnAndRow(17, $cont);

I don't think it's possible to specific a data type for a whole column. I may be wrong, maybe there's a way.

Jun 3, 2011 at 10:03 PM

I'd use the setCellValueExplicitByColumnAndRow() method.

$objPHPExcel->getActiveSheet()->setCellValueExplicitByColumnAndRow(17,$cont, $row[3], PHPExcel_Cell_DataType::TYPE_NUMERIC);