Topics: Developer Forum, User Forum
Mar 27, 2009 at 9:35 AM

Is there any examples on how to set data type on a range of cells?

I suppose, this can be done using duplicateStyleArray() method, but I found no examples on it both in dev documentation and PHPExcel API.
Mar 27, 2009 at 10:01 AM
Edited Mar 27, 2009 at 10:25 AM
well, i tried something like this:
(umm.. is there any tags to paste a code?)

                'alignment'     => array(        'horizontal'  => PHPExcel_Style_Alignment::HORIZONTAL_RIGHT ),
                'numberformat'  => array(        'formatcode'  => PHPExcel_Style_NumberFormat::FORMAT_NUMBER )

it executes without errors. horizontal alignment sets ok, but the format of cells is General. is it ok? may be cell's format overrides when i wrote something in it? but gettype() says that i write doubles..

                'alignment'     => array(        'horizontal'   => PHPExcel_Style_Alignment::HORIZONTAL_RIGHT),
                'numberFormat'  => array(        'formatCode'  => PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD)

and that code makes nothing as well. i suppose, i make something wrong, am i?

--edited x2

            $value = $grouppedArray_val_val['t_volume'];
            echo gettype($value);
            $objPHPExcel->getActiveSheet()->getCell("B$ind")->setValueExplicit($value, PHPExcel_Cell_DataType::TYPE_NUMERIC);

and that code makes the same. $value saves as 'General' though gettype() returns 'double'.
Mar 30, 2009 at 6:23 AM
When using a style array, you need to use array index 'code' rather that 'formatcode'. Check also "Appendix A" in the "PHPExcel Developer Documentation".

Mar 30, 2009 at 8:09 AM
Edited Mar 30, 2009 at 8:48 AM
it's funny, but "Appendix A" was the only place, that i didn't check looking for some manuals/examples. that's what i really need.

well, 'code' instead of 'formatcode' and '#,##0.000' as NumberFormat helps me.